[英]Ajax call on IE 9 (success data - undefined)
When calling specific service with ajax call IE9 returns "undefined": 使用ajax调用调用特定服务时,IE9返回“未定义”:
$.ajax({
url: URL_PATH,
type: "get",
success: function(data) {
console.log(data);
}
});
Inspecting same code in Firefox, Chrome, IE10+, it works. 在Firefox,Chrome,IE10 +中检查相同的代码,即可正常工作。 I even tried adding:
我什至尝试添加:
contentType: "application/json; charset=utf-8",
datatype: "json",
to ajax call properties, but no luck. Ajax调用属性,但没有运气。
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. 奇怪的是,当我调用本地JSON文件时,在IE9中一切正常,但是从本地服务器url(数据库信息)返回时,就会发生错误。 Taking a look at response body, I got well formatted json string.
看一下响应正文,我得到了格式正确的json字符串。
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" 但没有运气,它没有进入错误块,它捕获了“成功”
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.
我的休息服务的响应标头设置为charset = UTF8 ,并且IE无法识别其他浏览器正常工作时,正确的拼写需要为UTF-8,并带有破折号:)一个菜鸟错误。 Thanks everyone for suggestions.
感谢大家的建议。 Closing this thread now.
现在关闭该线程。
there are 3 ways to solve this issue, 有3种方法可以解决此问题,
First one add following lines, 第一个添加以下行,
<!--[if lte IE 9]>
<script type='text/javascript' src='//cdnjs.cloudflare.com/ajax/libs/jquery-ajaxtransport-xdomainrequest/1.0.0/jquery.xdomainrequest.min.js'></script>
<![endif]-->
Second one, 第二个,
solve it by using dataType='jsonp' at the place of dataType='json' 通过在dataType ='json'的位置使用dataType ='jsonp'来解决它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.