$ .getJson没有工作在IE [英] $.getJson not working in IE
问题描述
好吧,由于某种原因,我的getJSON不工作。我拉了一些股票信息和它的作品,除了IE浏览器的所有主流浏览器。
我已经创建了一个的jsfiddle这里: http://jsfiddle.net/qZhSk/
如果有人能帮助我理解我在做什么错了,它会是超级有帮助的。
谢谢!
修改
我找到了解决办法喽。这个问题是在我的网址查询。如果任何人有这个问题在这里就是答案:
VAR URL = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D'NPO'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
$ .getJSON(网址+&放大器;格式= JSON和放大器;回调=功能(数据){
变种项= [];
$每个(data.query.results.quote,功能(键,VAL){
items.push('<李ID =+按键+'>+ VAL +'< /李>');
});
$('< UL />',{
类:我的新列表,
的HTML:items.join('')
})appendTo(身体)。
)};
从技术上讲,我认为你侵犯了这一个同源策略。根据定义,你不能做的比你自己的域的JSON获得....从雅虎得到的数据肯定是不同的服务器的jsfiddle的。这里有一个报告类似的问题。中的CORS他们列出的例外是IE最高版本为10,这将完美地解释了这个问题。
的问题可以通过使用可以得到解决的?在你的回调处理程序。 看到这个堆栈文章更多信息。
Ok, for some reason my getJson is not working. I am pulling some stock information and it works in all major browsers except IE.
I have created a JSfiddle here: http://jsfiddle.net/qZhSk/
If anyone can help me understand what I am doing wrong it will be SUPER helpful.
thanks!
EDIT
I found the solution myself. The issue was in my URL query. If anyone else has this issue here is the answer:
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D'NPO'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
$.getJSON(url + "&format=json&callback=?", function(data) {
var items = [];
$.each(data.query.results.quote, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
)};
Technically, I think you're violating the Same Origin Policy on this one. By definition, you can't do a JSON get from a domain other than your own....and getting data from Yahoo is certainly a different server than jsFiddle's. There is a similar issue reported here. The CORS exceptions they list are IE up to version 10, which would explain the issue perfectly.
The problem could be solved by using a "?" in your callback handler. See this stack article for more info.
这篇关于$ .getJson没有工作在IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!