mui.ajax()
简介
mui封装了常用的Ajax函数,支持get、post请求方式,支持返回json、xml、html、text、script数据类型
分类
APP端,wkwebview,跨域情况下,使用plus.next.xmlHttpRequest
其他情况:window.xmlhttpRequest
用法格式
mui.ajax(url[,settings])
- url:必需参数,请发送地址,字符串型
- settings:可选参数async:布尔值,//同步请求data:object/{json},//发送到服务器数据dataType:返回值数据类型,//服务器返回数据类型xmlxml文档html纯文本htmlscript纯文本js代码jsonjson数据,常用类型error:function(xhr,type,errorThrown),//请求失败是触发的回调函数xhr:xhr实例对象type:错误描述,可取值timeoutabortparsererrornullerrorThrown:可捕获的异常对象timeout:number ,//请求超时时间,单位毫秒,默认为0,永不超时;若超时调用errortype:‘GET’,//请求方式,默认‘GET’GETPOSTheaders:json,//指定HTTP请求的header{‘Content-Type':'application/json'}//不能请求方式为POST时使用,后台无法获取数据{application/x-www-form-urlencoded}//post也可以使用,默认值processData:'true'//默认值,匹配headers默认值,将data参数传入的非字符串数据类型进行字符序列化,即转换为key1=value&key2=value2,其他格式设置为false
简化形式
mui.post(url[,data][,success][,dataType])
- mui.post(url,{},function(data){},'json')
mui.get(url[,data][,success][,dataType])
- mui.get(url,{},function(data){},'json')
mui.getJSON(url[,data][,success])
- mui.getJSON(url,{},function(data){},)
