jquery ajax请求时,设置请求头信息

设置一个名为 headers 的参数
参考代码:

// attempt to make an XMLHttpRequest to indeed.com
// jQuery 1.6.1  and Chrome  dev 13.0.767
function makeRequest() {
    alert("inside makeRequest()");
    var settings = {
        type: "GET",
        url:URL+"?"+REQUEST,
        dataType:"xml",
        error: function(XHR,textStatus,errorThrown) {
            alert ("XHR="+XHR+"\ntextStatus="+textStatus+"\nerrorThrown=" + errorThrown);
        },
        success: function(data,textStatus) {
            $("body").append(data);
        },
        headers: {
            "Access-Control-Allow-Origin":"http://example.edu",
            "Access-Control-Allow-Headers":"X-Requested-With"
        }
    };
    $.ajax(settings);
}
posted @ 2017-12-28 17:16  leigq  阅读(2244)  评论(0编辑  收藏  举报