的getJSON或AJAX请求不工作与IE9 [英] getJSON or AJAX requests not working with IE9

查看:159
本文介绍了的getJSON或AJAX请求不工作与IE9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图解决这个问题了几个小时(在这里搜索很好,但没有一个解决方案的工作),所以我没有别的选择,只能希望有人告诉我,为什么发生这种情况,我该如何解决这个问题。

这是一个简单的code,它与Firefox,但不与IE9的作品(没有其他版本)

例如code是在这里:

http://jsfiddle.net/z5b2J/

来源是这个:

  $。阿贾克斯({
  网址: "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",
  成功:函数(){
   警报('喜');
  }
});
 

网站并不需要是真正的用于测试目的。

正如你可以在Firefox下的小提琴看到,一个alertbox出现说但如果你在IE9运行完全相同的code时,alertbox不会出现。

同样的情况发生的getJSON方法,这是一个问题,对我来说,因为我要运行一些code,而不是警报,但它不会在IE9中运行。

解决方案

你有没有尝试使用的getJSON()而不是AJAX?这是一个跨域请求,你获取的JSON,以便它可能是问题。

它的两个浏览器现在的工作:

<$p$p><$c$c>$.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(){    警报('喜'); });

I have been trying to solve this problem for hours (searched here as well but none of the solutions worked) so I had no other option but to hope for someone to tell me why this is happening and how can I fix it.

This is a simple code that works with Firefox but not with IE9 (don't have other versions)

Example code is here:

http://jsfiddle.net/z5b2J/

Source is this one:

$.ajax({
  url: "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",
  success: function(){
   alert('hi');
  }
});

The website doesn't need to be real for testing purpose.

As you can see in the fiddle under Firefox, an alertbox appears saying "hi" BUT if you run the exact same code in IE9, the alertbox doesn't appear.

The same situation occurs with getJSON method, this is a problem for me because I want to run some code instead the alert but it won't run in IE9.

解决方案

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');
});

这篇关于的getJSON或AJAX请求不工作与IE9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆