getJSON or AJAX requests not working with IE9

房东的猫 提交于 2019-12-04 03:46:11

Did you try using getJSON() instead of ajax? This is a cross-domain request and you're fetching json so that it probably the problem.

It's working in both browsers now:

$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20script%20from%20html%20where%20url%3D%27https%3A%2F%2Ftesting.website.com%2F%3Fcid%3D48hgfd45430DD%26id%3D4830F8CF0454312%27&format=json&diagnostics=true&_maxage=86400&callback=?",function(){
   alert('hi');
});
bruce0wayne

The problem of IE9 depends on advanced cache management.

If you empty the cache of IE and re-run the ajax request: the first time will work.

To resolve this problem you must send your HTTP response with "noStore = true" and "Duration = 0" or equivalent.

Here is an example in MVC.

Using $.getJSON or $.ajax you must also specify dataType parameter 'jsonp'

Here the example using getJSON:

var webpage = ".... your very long url ....";
var anchor = document.createElement('a');
anchor.href = webpage;
// handle the multiple parameters
anchor.search += ((anchor.search.length > 0) ? "&" : "?");
anchor.search += "callback=?";

$.getJSON(anchor.href, 'jsonp',  function(data, textStatus, jqXHR){
   alert('hi');
});

I solved problem by adding "Duration=0" with the url

If you add callback=? to the URL, it will be transformed to something like callback=jQuery1820719005049791166_1366033695001 . It is the name of the function and on the server side you should wrap your json encoded object in this function call. So your response body should be not just {ok: true}, but jQuery1820719005049791166_1366033695001({ok: true}); . It worked for me!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!