0.1.1 • Published 9 years ago

tcb-missile v0.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

(AJAX) Missile

Tiny AJAX library that aims to be VERY similar to jQuery's $.ajax(settings) method.

Installation

npm install git://github.com/thecodebureau/missile.git

Usage

Works exactly like jQuery's $.ajax(settingsObject) function.

Missile({
  method: 'POST',
  url: '/api/objects',
  // one can also use dataType, like jQuery
  responseType: 'json',
  contentType: 'application/json',
  data: JSON.stringify({ key: 'value' }),
  success: function(response, textStatus, xhr) {
    console.log('success');
  },
  error: function(xhr, textStatus, errorThrown) {
    console.log('error');
  }
});

Set Defaults

To set defaults for any option to be used anytime it is not supplied (supports both Missile property names, or jQuery property names. See below.):

Missile.setDefaults({
  contentType: 'application/json;charset=UTF-8'
});

Compatability With & Differences to jQuery

Besides returning native XHR objects instead of jqXHR objects and dropping pre IE8 support, Missile aims to be 100% compatible with jQuery's $.ajax() function.

Renamed Options

TCB thinks some setting OPTIONS Are not named aptly considering property names of native XHR objects. Thus, the following have been renamed. To retain afore mentioned jQuery compatibility all jQuery property's are also still valid.

  • accepts -> accept
  • dataType -> responseType
  • type -> method

Implemented functionality

propertyimplementeddifferences to jQuery
acceptsYesAlso available as accept.
asyncNoN/A
beforeSendNoN/A
cacheNoN/A
completeYesNone
contentsNoN/A
contentTypeYesNone
contextNoN/A
convertersNoN/A
crossDomainNoN/A
dataYesOnly accept a string (must be set according to contentType) or an object if contentType is 'application/json'.
dataFilterNoN/A
dataTypeYesAlso available as responseType. Only accepts responseTypes accepted by the native XHR object. Which is 'arraybuffer', 'blob, 'document', 'json' and 'text'.
errorYesReturns a native XHR object instead of a jqXHR object. And it returns whatever you asked for with responseType/dataType. IE, if you asked for JSON you will get an error OBJECT back, not a status text or anything crazy like that.
globalNoN/A
headersYesNot sure of jQuery's default behaviour, but Missile overrites any properties that might have been set with accepts or similar.
ifModifiedNoN/A
isLocalNoN/A
jsonpNoN/A
jsonpCallbackNoN/A
mimeTypeNoN/A
passwordNoN/A
processDataYesThe processing can currently only create JSON string, not URL encoded.
scriptCharsetNoN/A
statusCodeNoN/A
successYesIt is passed a native XHR object instead of a jqXHR object.
timeoutNoN/A
traditionalNoN/A
typeYesAlso available as method.
urlYesNone
usernameNoN/A
xhrYesIn the default mode, it does not create ActiveXObject objects, only XMLHttpRequest objects
xhrFieldsNoN/A