bui.ajax Class
数据请求, $.ajax 跟 app.ajax 有的参数, bui.ajax 都有, 这里只列了简单的几个参数.
预览地址: demo
Constructor
bui.ajax
(
-
option
Parameters:
-
option
Object-
url
String[请求的地址]
-
data
Object[传输的数据对象 {} 不能是数组,原生不支持]
-
[method]
String optional[传输的方法 GET | POST]
-
[headers]
Object optional[通过header传输的参数 {} ]
-
[async]
Boolean optional[true 是异步 | false 是同步 ]
-
[dataType]
String optional[默认 json | jsonp | script | xml | html | text]
-
[contentType]
String optional[默认 'text/html;charset=UTF-8' | 'application/x-www-form-urlencoded'(表单) | 'multipart/form-data'(表单里有file文件) | 'application/json'(后端要用@requestbody接收) ]'
-
[timeout]
Number optional[超出这个时间则认为请求失败]
-
[needJsonString]
Boolean optional[1.4.6新增,默认 true|false. true时当contentType="application/json"并且data是对象的话,会尝试把数据转换为string. ]
-
Example:
bui.ajax({
url: "",
data: {}
}).then(function(res){
console.log(res)
},function(res,status){
console.log(status);
// status = "timeout" || "error" || "abort", "parsererror"
})