jrajax

1.0.9 • Public • Published

JRAjax

JRAjax is a minimalistic ajax framework for REST API which works with JSON as the medium of information transfer.

JRAjax uses XMLHttpRequest in older browsers and Fetch API in newer browsers.

Tech/framework used

JRAjax does not depend on any other frameworks and works independently. This is done to keep the code size minimal.

Features

JRAjax mainly focuses on JSON based REST API's. So it can be used extensively with JSON based API's

Installation

NODE
let JRAjax = require('jrajax');
...

Browser
<script src="JRAjax.min.js"></script>

...

API Reference

JRAjax.[method](URL, params[String/JSONObject], config[JSONObject]);

method: get, post, put, delete, head
params: 
      String param:  "param1=value1&param2=value2"
      JSONObject param:  {param1: value1, param2: value2}
config: 
      {
        successHandler: {
          func: ,//A function reference. NOTE - 200 HTTP Response will go into this handler.
          ctx: //Context with with the function should get executed
        },
        failureHandler: {
          func: ,//A function reference. NOTE - 400 - 499 HTTP Responses will go into this handler.
          ctx: //Context with which the function should get executed
        },
        errorHandler: {
          func: ,//A function reference. NOTE - 500 - 599 HTTP Responses will go into this handler.
          ctx: //Context with which the function should get executed
        },
        loader: HTMLElement/Id of the element,//The classname will be appeded with 'ing' during request processing
                                              //Eg: 'loaded' will become 'loading'. Note: a default loader will be 
                                              //created if not given
                                              
        noloader: true/false, //if no loader should be called
      }

handlers - Will be called with two params

  1. server response
  2. config. So you could also provide your own config which you intend to use inside the handlers upon request completion.

Package Sidebar

Install

npm i jrajax

Weekly Downloads

1

Version

1.0.9

License

MIT

Unpacked Size

68.4 kB

Total Files

14

Last publish

Collaborators

  • jpsam7