Micro library for making AJAX requests - 857 bytes minified
See a demo here https://lucianbuzzo.github.io/luigi/.
Simple use a script tag to load luigi at the bottom of your pages <body> tag.
<script src="luigi.js"></script>Calling the luigi function directly will run luigi.get().
- luigi
- .get(url, callback) ⇒
Object - .getJSON(url, callback) ⇒
Object - .getHTML(url, elementId, callback) ⇒
Object - .post(url, data, callback) ⇒
Object
- .get(url, callback) ⇒
Kind: static method of luigi
Summary: Sends a GET request to a url
Returns: Object - - An XMLHttpRequest object.
Access: public
| Param | Type | Description |
|---|---|---|
| url | String |
The url to send a request to |
| callback | function |
callback(responseText) |
Example
luigi.get('/example.html', function callback(responseText) {
console.log(responseText);
});Sends a GET request to a url that serves JSON. Data is parsed before being passed to the callback function.
Kind: static method of luigi
Summary: Sends a GET request to a url that serves JSON.
Returns: Object - - An XMLHttpRequest object.
Access: public
| Param | Type | Description |
|---|---|---|
| url | String |
The url to send a request to |
| callback | function |
callback(responseData) |
Example
luigi.getJSON('/example.html', function callback(responseData) {
console.log(responseData);
});Kind: static method of luigi
Summary: Retrieves the contents of an HTML element from a page loaded with AJAX
Returns: Object - - An XMLHttpRequest object.
Access: public
| Param | Type | Description |
|---|---|---|
| url | String |
The url to send a request to |
| elementId | String |
The id of the element to search for |
| callback | function |
function called with the content of the HTML element if present, else an empty string. |
Example
var html = '<p><h1>FOO</h1><span id="subtitle">BAR</span></p>';
var element = pickHTML(html, 'subtitle');
console.log(element); // --> 'BAR'Kind: static method of luigi
Summary: Sends a post request via AJAX
Returns: Object - - An XMLHttpRequest object.
Access: public
| Param | Type | Description |
|---|---|---|
| url | String |
The url to send a request to |
| data | Object |
The data to send as the request body |
| callback | function |
function called with response test from the server |
Example
luigi.post('/example-endpoint', { foo: 'bar' }, function(responseText) {
console.log(responseText);
});