MUI AJAX Raw请求数据

时间:2023-03-09 07:15:28
MUI AJAX Raw请求数据

提交接口数据,接口方提供的是post请求,body - raw ;

我尝试过JQuery ajax raw 的方式,但是始终无法成功

然后我回想到我用的是mui我就开始考虑用mui.ajax结果就成功了,特此记录下。其实也是也是自己走了弯路,本来用mui,最好的还是用它的全部东东

代码分享一下:

 (function () {

     window.ax = {
api:"http://127.0.0.1/", // 这里需要替换为你的接口IP // GET 提交方式
// u --请求地址
// f --回调函数 成功 function(data){} ; 失败 function(xhr,type,errorThrown){}
g:function(u,f){
mui.get( ax.api + u,{},f,"json");
}, // POST 提交方式
// u --请求地址
// p --发送数据 $(id) 例子: "#id",{id:1}
// f --回调函数 成功 function(data){} ; 失败 function(xhr,type,errorThrown){}
p:function(u,p,f) {
if(typeof(p) === "string") {
p = $(p).serializeObject();
}
mui.ajax(ax.api + u,{
data: p,
dataType: 'json',
type: 'post',
headers: {'Content-Type':'application/json'},
success: f,
error: f
});
}
} })(); // 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: zhengsh 2016-9-5
var o = {
"M+": this.getMonth() + , //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + ) / ), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$, (this.getFullYear() + "").substr( - RegExp.$.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$, (RegExp.$.length == ) ? (o[k]) : (("" + o[k]).substr(("" + o[k]).length)));
return fmt;
} // 表单对象转换为JSON
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if(o[this.name]) {
if(!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};