Sam*_*m3k 6 javascript ajax jquery internet-explorer json
我有以下ajax调用,它在Firefox和Chrome中完美运行但不是IE:
function getAJAXdates( startDate, numberOfNights, opts ) {
var month = startDate.getMonth() + 1;
var day = startDate.getDate();
var year = startDate.getFullYear();
var d = new Date();
var randNum = Math.floor(Math.random()*100000000);
$.ajax({
type : "GET",
dataType : "json",
url : "/availability/ajax/bookings?rand="+randNum,
cache : false,
data : 'month='+month+'&day='+day+'&year='+year+'&nights='+numberOfNights,
contentType : 'application/json; charset=utf8',
success : function(data) {
console.log('@data: '+data);
insertCellData(data, opts, startDate);
},
error:function(xhr, status, errorThrown) {
console.log('@Error: '+errorThrown);
console.log('@Status: '+status);
console.log('@Status Text: '+xhr.statusText);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我知道所有变量都传递了正确的内容,$ .ajax确实传递了所有参数/值.
这是我得到的错误:
日志:@Error:未定义日志:@Status:parsererror日志:@Status文本:好的
我知道IE上的缓存问题并实现了一个随机参数来清除它.
这是我回来的JSON(我能用Charles查看)
{
"availability":[
{
"inventory_id":"5",
"booking_id":"21",
"start_date":"05-01-2010",
"number_nights":4,
"text":"deFrancisco, Martin - $500.00 ACTIVE",
"type":"BOOKING"
}
]
}
Run Code Online (Sandbox Code Playgroud)
最后这些是从后端发回的标头:
header('Content-Type: application/json; charset=utf8');
header("Cache-Control: no-cache");
header("Expires: 0");
header('Access-Control-Max-Age: 3628800');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我会注释掉 contentType 并添加 dataType: "json"
来自http://api.jquery.com/jQuery.ajax/
dataType:您期望从服务器返回的数据类型。
contentType:向服务器发送数据时,使用此内容类型。
您指定要发送 json,但实际上没有 - 也许这就是问题所在?