Firefox 中出现无效标签错误

发布于 2024-12-05 09:37:39 字数 867 浏览 0 评论 0原文

当我从另一个域接收一些 json 内容时,我在 Firefox 中收到无效标签错误。我的 JS 代码是:

$.getJSON('http://www.upsidelearning.com/blog/blogapp/getBlogDetails.php?getBlogsList=1&jsoncallback=?', function(data){
     alert("Success");
      }); 

并且在 chrome 错误控制台中收到以下错误:

(Warning)Resource interpreted as Script but transferred with MIME type text/html.
(Error) Uncaught SyntaxError: Unexpected token :

编辑:我的响应 json 是:

{"data":[{"title":"How Long Does It Take To Develop An Hour Of Elearning?","publishDate":"15 September 2011","author":"Abhijit Kadle","permalink":"http:\/\/www.upsidelearning.com\/blog\/index.php\/2011\/09\/15\/how-long-does-it-take-to-develop-an-hour-of-elearning\/","thumbnail":"http:\/\/www.upsidelearning.com\/blog\/blogapp\/images\/blogpost-icon.png","id":9197}]}

请帮助我。

I am getting Invalid label error in firefox while receiving some json content from another domain. My JS code is :

$.getJSON('http://www.upsidelearning.com/blog/blogapp/getBlogDetails.php?getBlogsList=1&jsoncallback=?', function(data){
     alert("Success");
      }); 

And In chrome error console following error received :

(Warning)Resource interpreted as Script but transferred with MIME type text/html.
(Error) Uncaught SyntaxError: Unexpected token :

EDIT : My response json is :

{"data":[{"title":"How Long Does It Take To Develop An Hour Of Elearning?","publishDate":"15 September 2011","author":"Abhijit Kadle","permalink":"http:\/\/www.upsidelearning.com\/blog\/index.php\/2011\/09\/15\/how-long-does-it-take-to-develop-an-hour-of-elearning\/","thumbnail":"http:\/\/www.upsidelearning.com\/blog\/blogapp\/images\/blogpost-icon.png","id":9197}]}

Please help me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ら栖息 2024-12-12 09:37:40

问题是服务器端脚本没有为任何回调添加前缀。你需要解决这个问题。它返回纯 JSON,如果不将其传递到函数或回调中就无法执行。

The problem is that the server side script isn't prefixing any callback. You need to get that fixed. It's returning plain JSON which cannot be executed without passing it into a function or callback.

提赋 2024-12-12 09:37:39

当我从另一个域接收一些 json 内容时,我在 Firefox 中收到无效标签错误。

由于同源策略限制,不允许将AJAX请求发送到不同的域。有几种解决方法:

  1. 使用 JSONP。 getJSON() 文档中有一个关于它的特定部分。仅当远程域支持时才有效。例如,而不是:

    {"data":[{"title":"开发一个小时的电子学习需要多长时间?","publishDate":"2011 年 9 月 15 日","author":"Abhijit Kadle","permalink":"http:\/\/www.upsidelearning.com\/blog\/index.php\/2011\/09\/15\/how-long-does-it-take-to-开发-在线学习时间\/","缩略图":"http:\/\/www.upsidelearning.com\/blog\/blogapp\/images\/blogpost-icon.png","id":9197}] }
    

    远程域必须能够返回:

    callback({"data":[{"title":"开发一个小时的电子学习需要多长时间?","publishDate":"2011 年 9 月 15 日","author":"Abhijit Kadle","permalink":"http:\/\/www.upsidelearning.com\/blog\/index.php\/2011\/09\/15\/how-long-does-it-take-to-开发-an-h our-of-elearning\/","thumbnail":"http:\/\/www.upsidelearning.com\/blog\/blogapp\/images\/blogpost-icon.png","id":9197}] })
    

    客户端可以在其中设置回调名称。

  2. 如果 JSONP 不是一个选项,您可以在您的域上编写一个服务器端脚本,该脚本将充当您的域和远程域之间的桥梁,然后将 AJAX 请求发送到您的脚本。

    如果


更新:

经过大量评论后,您似乎正在尝试使用 YQL。这是一个完整的工作演示

$.get('http://www.upsidelearning.com/blog/blogapp/getBlogDetails.php?getCategories=1&callback=?', function(result) {
    // you could parse the JSON like this:
    // var json = $.parseJSON(($(result.responseText).filter('p').text()));
    // alert(json.data[0].id);

    alert("Success");
});

请注意,您应该使用 $.get 而不是 <代码>$.getJSON。

I am getting Invalid label error in firefox while receiving some json content from another domain.

Due to the same origin policy restriction it is not allowed to send AJAX requests to different domains. There are a couple of workarounds:

  1. Use JSONP. There is a specific section about it in the getJSON() documentation. Works only if the remote domain supports it. So for example instead of:

    {"data":[{"title":"How Long Does It Take To Develop An Hour Of Elearning?","publishDate":"15 September 2011","author":"Abhijit Kadle","permalink":"http:\/\/www.upsidelearning.com\/blog\/index.php\/2011\/09\/15\/how-long-does-it-take-to-develop-an-hour-of-elearning\/","thumbnail":"http:\/\/www.upsidelearning.com\/blog\/blogapp\/images\/blogpost-icon.png","id":9197}]}
    

    the remote domain must be able to return:

    callback({"data":[{"title":"How Long Does It Take To Develop An Hour Of Elearning?","publishDate":"15 September 2011","author":"Abhijit Kadle","permalink":"http:\/\/www.upsidelearning.com\/blog\/index.php\/2011\/09\/15\/how-long-does-it-take-to-develop-an-hour-of-elearning\/","thumbnail":"http:\/\/www.upsidelearning.com\/blog\/blogapp\/images\/blogpost-icon.png","id":9197}]})
    

    where the client could set the callback name.

  2. If JSONP is not an option you could write a server side script on your domain that will act as a bridge between your domain and the remote domain and then send the AJAX request to your script.


UPDATE:

After the numerous comments it seems that you are trying to use YQL. Here's a full working demo:

$.get('http://www.upsidelearning.com/blog/blogapp/getBlogDetails.php?getCategories=1&callback=?', function(result) {
    // you could parse the JSON like this:
    // var json = $.parseJSON(($(result.responseText).filter('p').text()));
    // alert(json.data[0].id);

    alert("Success");
});

Notice that you should use $.get and not $.getJSON.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文