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);
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM