在IE 9 Ajax调用(成功的数据 - 未定义) [英] Ajax call on IE 9 (success data - undefined)
问题描述
当调用特定的服务与Ajax调用IE9将返回未定义:
When calling specific service with ajax call IE9 returns "undefined":
$.ajax({
url: URL_PATH,
type: "get",
success: function(data) {
console.log(data);
}
});
检查同一code在火狐,Chrome,IE10 +,它的工作原理。我甚至尝试添加:
Inspecting same code in Firefox, Chrome, IE10+, it works. I even tried adding:
contentType: "application/json; charset=utf-8",
datatype: "json",
要Ajax调用性能,但没有运气。
to ajax call properties, but no luck.
奇怪的是,当我叫本地JSON文件,一切都还好在IE9中,而是从本地服务器的URL(信息从数据库)返回时发生错误。纵观响应主体,我得到了良好的格式化JSON字符串。
Strange thing is that when I call a local JSON file, everything is okay in IE9, but when returning from local server url (information from database) that error occurs. Taking a look at response body, I got well formatted json string.
更新: 还增加了错误捕获块:
UPDATE: Also added the error catching block:
error: function(XMLHttpRequest)
{
console.log(XMLHttpRequest);
},
但没有运气,它不走错误块中,它捕获成功
but no luck, it doesn't go inside the error block, it catches "success"
推荐答案
我发现了一个问题。我休息服务的响应头被设置为的charset = UTF8 和IE浏览器无法识别,而其他浏览器没有问题的工作,正确的拼写必须是 UTF-8 以短线:)一个新手的错误。谢谢大家的建议。现在关闭这个线程。
I found a problem. The response header of my rest service was set to charset=UTF8 and the IE couldn't recognize that while other browsers work with no problem, the correct spelling needs to be UTF-8 with a dash :) a rookie mistake. Thanks everyone for suggestions. Closing this thread now.
这篇关于在IE 9 Ajax调用(成功的数据 - 未定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!