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

axjs

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axjs

A microscopic, RESTful, AJAX browser library; just under 2kb.

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Ax.js

A microscopic, RESTful, AJAX browser library; just under 2kb.

  • Usage
  • Examples

Installation:

Ax

var request = new Ax( Object || Arguments); 

Arguments Method

var request = new Ax(method, url, [data], [type], done);
Arguments
  1. method (String): http request (e.g., GET, PUT, POST, PATCH, DELETE, etc...)
  2. url (String): location/href
  3. [data] (Object|JSON): required if uploading data to the server
  4. [type] (String): Content-Type header (default is application/json)
  5. done (Function) Callback when request is finished, is always the last argument passed.

Object Method

Similar approach, see arguments above for explanation of values...

var request = new Ax({
  method: method,
  url: url,
  data: [data],
  type: [type],
  done: done
}, [done]);

NOTE: the done callback can either be in the first argument that is an object, or the last argument; but not both. If a function is detected as the last argument, Ax will use that and ignore the other.

Callback

The done callback function is passed as the last argument.

var request = new Ax(...args, function (res, xhr, err) {
  // Single error detection
  if (err) {
    // Whoops lets do something
  }
  console.log('response is', res);
});

It may also be part of the options object

var request = new Ax({
  ...options,
  done: function (res, xhr, err) {    
    if (err) console.error(err);
    console.log(res, xhr);
  }
});

Examples

Get user data...

var request = new Ax('GET', '/users/' + userid', function (res, xhr, err) {
  if (err) {
    // An error has occurred
  } else {
    var userdata = res;
    // Do something with user data.
  }
});

Update a user profile...

var request = new Ax({
  method: 'PUT',
  url: userUrl,
  data: newData,,
  done: callBack()
});

Post a form...

var request = new Ax('POST', '/submit/', formData, function (res, xhr, err) {
  if (err) {
    alert ('total failure', err);
  } else {
    console.log('server response is', res);
  }
});

Browser

<script src="ax.min"></script>

NodeJS

Ax.js has been built with browserify, and works with both browserify and webpack.

Install via npm:

npm install axjs

require the module

var Ax = require('axjs');

CommonJS

Ax.js can be required in with a UMD or AMD library like requirejs.

var Ax = require('ax');

Keywords

FAQs

Package last updated on 09 May 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