老千
老千
  • 发布:2015-08-10 19:38
  • 更新:2016-04-15 10:56
  • 阅读:4350

ajax如何设置header

分类:MUI

mui的资料太不详细啦,完全不知道怎么设置ajax的header等?

2015-08-10 19:38 负责人:无 分享
已邀请:
MrP

MrP

同问。。。。。。。。。。。。。。。。

云海帆

云海帆 - 咨询问题请+Q1395641578

这是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;
MrP

MrP

mui.ajax(url,   
{  
    data:{"value":mui.jsonPrivate3Des(params)},  
    setting:{headers:{"SessionId" : user.SessionId}},  
    type:"post",  
    success:function(data){  
            console.log(JSON.stringify(data));  
        if(data.StatusCode == 1){                     
            console.log(data.Data.sn);  
            mui.toast(data.Msg);  
        }else{  
            mui.toast(data.Msg);  
        }  
    }  
})

这样写对吗?

云海帆

云海帆 - 咨询问题请+Q1395641578

$.ajax({  
                url: url,  
                type : type,  
                headers: {},  
                data: data,  
                success: success,  
                dataType: dataType,  
            })
  • 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

alex_zuo

headers:{"apikey":'xxx'},//亲测可行

该问题目前已经被锁定, 无法添加新回复