[英]Error: MIME type ('application/json') is not executable, and strict MIME type checking is enabled with YQL statements?
I was trying to run an example about YQL from Yahoo . 我试图从Yahoo运行一个有关YQL的示例。 This is the code that I am supposed to use: 这是我应该使用的代码:
<body>
<div id='results'></div>
<script src='https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20rss%20where%20url%3D%22http%3A%2F%2Frss.news.yahoo.com%2Frss%2Ftopstories%22&format=json&diagnostics=true&callback='></script>
</body>
<script type='text/javascript'>
function top_stories(o){
var items = o.query.results.item;
var output = '';
var no_items=items.length;
for(var i=0;i<no_items;i++){
var title = items[i].title;
var link = items[i].link;
var desc = items[i].description;
output += "<h3><a href='" + link + "'>"+title+"</a></h3>" + desc + "<hr/>";
}
document.getElementById('results').innerHTML = output;
}
</script>
I have read other question with same error and most of them give an answer similar to this one 我已经阅读了另一个具有相同错误的问题,其中大多数给出的答案与此相似
By adding a callback argument, you are telling jQuery that you want to make a request for JSONP using a script element instead of a request for JSON using XMLHttpRequest. 通过添加一个回调参数,您告诉jQuery您想使用脚本元素而不是使用XMLHttpRequest来请求JSONP来请求JSONP。 JSONP is not JSON. JSONP不是JSON。 It is a JavaScript program. 这是一个JavaScript程序。
My problem is I am using JavaScript and I can't find the code in above script where I am expecting JSONP. 我的问题是我正在使用JavaScript,但是在我期望JSONP的上述脚本中找不到代码。 I am a complete newbiw so may be I have made a silly mistake. 我是新手,所以我可能犯了一个愚蠢的错误。 What is wrong with the code above? 上面的代码有什么问题? Thanks. 谢谢。
The <script>
element on line 3 is requesting the JSONP. 第3行的<script>
元素正在请求JSONP。 It's just hard coded to do it instead of being added with JS (which would be normal for JSONP). 只是很难做到这一点,而不是使用JS添加(对于JSONP来说是正常的)。
YQL is delivering JSON because you've said callback=
and then stopped without actually providing a callback function name. YQL正在传递JSON,因为您已经说过callback=
,然后在没有实际提供回调函数名称的情况下停止了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.