Files
antd-admin/src/utils/request.js
T
2016-12-12 23:36:59 +08:00

30 lines
811 B
JavaScript

const Ajax = require("robe-ajax")
/**
* Requests a URL, returning a promise.
*
* @param {string} url The URL we want to request
* @param {object} [options] The options we want to pass to "fetch"
* @return {object} An object containing either "data" or "err"
*/
export default function request(url, options) {
if (options.cross) {
return Ajax.getJSON("http://query.yahooapis.com/v1/public/yql", {
q: "select * from json where url=\'"+url+"?"+Ajax.param(options.data)+"\'",
format: "json"
})
} else {
return Ajax.ajax({
url: url,
method: options.method || 'get',
data: options.data || {},
processData: options.method == 'get'
? true
: false,
dataType: 'JSON'
}).done((data) => {
return data
})
}
}