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

你可能感兴趣的:(jquery ajax请求时,设置请求头信息)