这是mui的源码
var setHeader = function(name, value) {
headers[name.toLowerCase()] = [name, value];
};
var protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol;
var xhr = settings.xhr(settings);
var nativeSetHeader = xhr.setRequestHeader;
var abortTimeout;
setHeader('X-Requested-With', 'XMLHttpRequest');
setHeader('Accept', mime || '*/*');
if (!!(mime = settings.mimeType || mime)) {
if (mime.indexOf(',') > -1) {
mime = mime.split(',', 2)[0];
}
xhr.overrideMimeType && xhr.overrideMimeType(mime);
}
if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() !== 'GET')) {
setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded');
}
if (settings.headers) {
for (var name in settings.headers)
setHeader(name, settings.headers[name]);
}
xhr.setRequestHeader = setHeader;
7 个回复
MrP
同问。。。。。。。。。。。。。。。。
云海帆 - 咨询问题请+Q1395641578
这是mui的源码
MrP
这样写对吗?
云海帆 - 咨询问题请+Q1395641578
alex_zuo
headers:{"apikey":'xxx'},//亲测可行
2016-04-18 10:51
甜甜爸
同问
甜甜爸
var xhr = new plus.net.XMLHttpRequest();
xhr.responseType="json";
xhr.onreadystatechange = function () {
switch ( xhr.readyState ) {
case 4:
if ( xhr.status == 200 ) {
plus.nativeUI.toast('验证码已发送到您的手机。');
} else {
//plus.nativeUI.toast('发送失败');
}
break;
default :
break;
}
}
xhr.open( "POST", "http://ddd.ddd.com/Service/ServiceUser.svc/SendTelCode");
var data={mobile:accountBox.value};
xhr.setRequestHeader('Content-Type','application/json');
xhr.send(JSON.stringify(data));
alex_zuo