Skip to content
/ Echo Public

A concentrated (ES6) library for Ajax requests.

License

Notifications You must be signed in to change notification settings

HLSiira/Echo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT

About

Echo is a concentrated library for making Ajax requests, built off of WeideMo's MiniAjax. Weighing in at under 100 lines of code, Echo provides a convenient interface for Ajax requests, both GET and POST. It also provides innate JSON parsing where possible. Echo was built in order to be used as a compact and intuitive Ajax library for development on the Atheos IDE, however it's proved so valuable as to become it's own mini library. Echo returns the XMLHttpRequest in order to faciliate aborts, and encourage further customization. Only the URL is required in order to send an Echo; All other options are optional and the type defaults to POST.

Features

Pleasently Parsed: Echo automatically tries to parse JSON replies.

Crazily Condensed: The minified version is less than ~1K, roughly 500b gzipped.

Easily Extensible: Echo is easily modifyable to meet your needs.

Usage

Argument Required Type
url true string
type false ["POST" || "GET"]
data false object
Argument Required Type
timeout false integer
success false function
failure false function

Below is the typical structure for utilizing sending an Echo:

document.addEventListener('DOMContentLoaded', function() {
	'use strict';
	echo.setHeaders({
		'x-csrf-token': '<?php echo(CSRFTOKN) ?>'
	});
});

echo({
    url: "./testXhr.php",                // Destination URL
    type: "POST",                        // Request Type: POST (default) or GET
    data: { name: "WeideMo", age: 26 },  // Data sent to the server
    timeout: 5000,						 // Time in Milliseconds
    settled: function (reply, httpResponseCode) {
        // Function called on either success or failure
    },    
    success: function (reply, httpResponseCode) {
        // Function called on success
    },
    failure: function (reply, httpResponseCode) {
        // Function called on failure
    }
});

About

A concentrated (ES6) library for Ajax requests.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project