Skip to content

Repository files navigation

luigi

Micro library for making AJAX requests - 857 bytes minified

See a demo here https://lucianbuzzo.github.io/luigi/.

Usage

Simple use a script tag to load luigi at the bottom of your pages <body> tag.

<script src="luigi.js"></script>

Documentation

Calling the luigi function directly will run luigi.get().

luigi.get(url, callback) ⇒ Object

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);
});

luigi.getJSON(url, callback) ⇒ Object

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);
});

luigi.getHTML(url, elementId, callback) ⇒ Object

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'

luigi.post(url, data, callback) ⇒ Object

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);
});

About

Micro library for making AJAX requests - 857 bytes minified

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages