Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fdaciuk/ajax

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fdaciuk/ajax

Ajax module in Vanilla JS

  • 0.0.10
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
178
increased by286.96%
Maintainers
1
Weekly downloads
 
Created
Source

Ajax

Ajax module in Vanilla JS

Ajax

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

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.9/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

Keywords

FAQs

Package last updated on 12 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc