自定义 ajax 调用以 & 符号.js

Custom ajax calls in ampersand.js

本文关键字:符号 js ajax 调用 自定义      更新时间:2023-09-26

我知道model/collection RESTful东西。但是我需要在ampersand.js中自定义ajax调用,但我似乎找不到它的API。我应该回退到使用普通的旧xmlhttprequest吗?

如果使用自定义调用来填充model/collection,则应考虑使用 ajaxConfig 选项。

否则,你可以只使用ampersand-sync自身使用的像xhr这样的模块来抽象xmlhttprequest,例如:

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