Giter VIP home page Giter VIP logo

ajax's Introduction

Ajax

Ajax module in Vanilla JS

Ajax

Build Status Coveralls Coverage Status Code Climate Coverage Code Climate License CONTRIBUTING

You can use this module with AMD, CommonJS or just like a method of window object!

Installation

Bower

You can install via bower:

bower install ajax

Manual installation

Just download dist/ajax.min.js file, and add dist/ajax.min.js on your HTML file:

<script src="js/ajax.min.js"></script>

CommonJS (via NPM)

npm i --save @fdaciuk/ajax

CDN

You can just add the following line to your HTML file:

<script src="https://cdnjs.cloudflare.com/ajax/libs/fdaciuk-ajax/0.0.12/ajax.min.js"></script>

Usage

AMD

define([ 'Ajax' ], function( Ajax ) {
  var ajax = new Ajax();
  ...
});

CommonJS

var Ajax = require( '@fdaciuk/ajax' );
var ajax = new Ajax();
...

Method of window object

var ajax = new window.Ajax();

or

var ajax = new Ajax();

Enjoy ;)

Methods

get(url)

Get data as a JSON object.

var ajax = new Ajax();
ajax.get( '/api/users' );
ajax.get( '/api/users/john' );

post(url, [ data ])

Save a new register or update part of this one.

var ajax = new Ajax();
ajax.post( '/api/users', { slug: 'john' });

put(url, [ data ])

Update an entire register.

var ajax = new Ajax();
ajax.put( '/api/users', { slug: 'john', age: 37 });

delete(url, [ data ])

Delete a register.

var ajax = new Ajax();
ajax.delete( '/api/users', { id: 1 });

Return methods

done(response, xhrObject)

Promise that returns if the request was successful.

var ajax = new Ajax();
ajax.get( '/api/users' ).done(function( response, xhr ) {
  // Do something
});

error(response, xhrObject)

Promise that returns if the request has an error.

var ajax = new Ajax();
ajax.post( '/api/users', { slug: 'john' }).error(function( response, xhr ) {
  // Do something
});

always(response, xhrObject)

That promise always returns, independent if the status is done or error.

var ajax = new Ajax();
ajax.post( '/api/users', { slug: 'john' }).always(function( response, xhr ) {
  // Do something
});

Contributing

Check CONTRIBUTING.md

Code coverage and Statistics

https://github.com/reportz/ajax

License

MIT © Fernando Daciuk

ajax's People

Contributors

brunoventura avatar fdaciuk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.