Search code examples
javascriptajaxampersand.js

Custom ajax calls in ampersand.js


I know model/collection RESTful stuff. But I need to make custom ajax calls in ampersand.js, but I can't seem to find the API for it. Should I just fall back to using plain old xmlhttprequest instead?


Solution

  • If the custom call is used to populate a model/collection, you should consider using the ajaxConfig option.

    Otherwise you can just use a module like xhr that ampersand-sync uses itself, to abstract the xmlhttprequest, for example:

    var xhr = require("xhr")
    
    xhr({
      body: someJSONString,
      uri: "/foo",
      headers: {
        "Content-Type": "application/json"
      }
    }, function (err, resp, body) {
      // check resp.statusCode
    })