Pla*_*own 5 ajax jquery internet-explorer-8
ajax调用在FF中工作正常.返回的数据是JSON,这里是FF firebug的一个例子 -
{"noProfiles":"没有创建配置文件,现在就开始吧!"}
当我尝试在IE8中打印错误时(以及在兼容模式下),它会显示"parsererror".
但输出似乎是有效的JSON.
这是我正在制作的ajax函数调用.
任何指针都会很棒!
$.ajax({
type: "GET",
url: "/get_all_profile_details/",
data: "",
dataType: "json",
beforeSend: function() {alert("before send called");},
success: function(jsonData) {
alert("data received");
},
error: function(xhr, txt, err){
alert("xhr: " + xhr + "\n textStatus: " + txt + "\n errorThrown: " + err);
}
});
Run Code Online (Sandbox Code Playgroud)
上面的错误函数中的警报给出 -
xhr:<blank>
textstatus:parsererror
errorThrown: undefined
任何指针都会很棒!
注意:jquery:1.3.2
这是我终于找到的解决方案!
IE是关于UTF-8的肛门,不仅如此!
我正在制定我的回复如下:
return HttpResponse(simplejson.dumps(response_dict),
content_type = 'application/json; charset=utf8')
Run Code Online (Sandbox Code Playgroud)
现在FF和Chrome很好用.
但对于IE,utf8应该是这样的:
return HttpResponse(simplejson.dumps(response_dict),
content_type = 'application/json; charset=UTF-8')
Run Code Online (Sandbox Code Playgroud)
请注意大写UTF - >> UTF-8
为了调试这个问题,我扔了我的jquery并编写了一个简单的ajax函数.
var xmlhttp = false;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST",urlToSend,false);
xmlhttp.send(af_pTempString);
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST",urlToSend,false);
// Do not send null for ActiveX
xmlhttp.send(af_pTempString);
}
//alert("xmlhttp.responseText : " + xmlhttp.responseText);
document.getElementById('navHolder').innerHTML = xmlhttp.responseText;
Run Code Online (Sandbox Code Playgroud)
如果编码不正确,它会在IE中给你这个错误 - c00ce56e
| 归档时间: |
|
| 查看次数: |
3914 次 |
| 最近记录: |