我正在尝试发送跨域 ajax GET 请求
$(document).ready(function(){
$.ajax
({
type: "GET",
url: "url",
cache: false,
contentType: "application/x-www-form-urlencoded",
dataType: "jsonp",
beforeSend: function (xhr){
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader('Authorization', make_base_auth("login", "pwd"));
},
success: function (data, success){
console.log("success", arguments);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error", arguments);
},
complete: function(jqxhr, textStatus) {
console.log("complete", arguments);
}
});
});
服务器只接受 application/x-www-form-urlencoded 数据。发送请求后,我收到 415 状态的响应(不支持的媒体类型)当我在 firebug 中检查标头时,我根本看不到 Content-Type 标头。
GET /url?callback=jsonp1374315852923&_=1374315854258 HTTP/1.1
Host: hostname
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://refferer
Cookie: JSESSIONID=1DCD5D9EB35FEF083C7EAF8F7EA25D54; ltime=1374315850; lid=30000379384174; SESS826f62d511330ecdaa9034d04e399c65=qj2jcempp4osi2hc00lq1jnkp1; AA_SESS=2c-30f9987cd946; AA_UID=0fe8965d05c37706a5bfbec88629ed68
Authorization: Basic YWthdml0YTpQNlBhdQ==
Connection: keep-alive
非常感谢您的意见!