0.1.9-development • Published 8 years ago

ajax-elements v0.1.9-development

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Ajax elements

Make your links perform ajax call

  • Set links behaviour:
<a href="/auth/logout" 
    data-method="POST" 
    data-callback="redirectHome">Logout</a>

<a href="/news" 
    data-method="GET" 
    data-params="sort=created_at&order=desc" 
    data-callback="updateElement(.status)|showMessage|log">Get News</a>
  • Set elements selector and callbacks:
import {AjaxLinksSettings} from 'ajax-links';

AjaxLinksSettings.setSelector('.ajaxLink');
AjaxLinksSettings.setCallbacks({
    redirectHome() {
        location.href = '/';
    },
    
    updateElement(response, $elements) { // querySelectorAll used, you may wrap to jQuery
        $elements[0].innerHTML = response.status;
    },
    
    showMessage(response) {
        alert(response.message);
    },
    
    log(response) {
        console.log(response);
    }
});

Installation

yarn add ajax-elements or npm install ajax-elements --save

Documentation:

  • Links:

    • href = URL
    • data-method = GET, POST (default), PUT, PATCH, DELETE, HEAD
    • data-params = sort=id&order=desc (key=value&key2=value2)
    • data-callbacks = "log|closeModal" callbacks names (can be piped with "|", and parametrized with selectors)
  • Callbacks:

    • First argument is response
    • Other arguments are queried with document.querySelectorAll
0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago