$.getJSON 在检索数据时出现无提示错误

发布于 2024-11-01 22:43:45 字数 2401 浏览 0 评论 0原文

我尝试从 JSon 服务检索数据,但遇到一些问题,无法通过调试过程。

我从这个动态服务中检索数据: http://www.synergiescanada .org/json/otherpublicationbyid?synid=synergies:bcn.arbutus.215.3263 我使用此工具验证结果 http ://jsonformatter.curiousconcept.com/ 看起来不错。

[
   {
      "name":"Dr. Andre Smith",
      "publications":[
         {
            "id":"synergies:bcn.arbutus.215.3264",
            "title":"Exploring death and dying through discourse",
            "uri":"http:\/\/journals.uvic.ca\/index.php\/arbutus\/article\/view\/3264",
            "date":"2010-10-18"
         }
      ]
   }
]

但以另一种方式,当我使用 jquery 中的 .getJSON 方法时,它会失败。

<script type="text/javascript"> 
$(document).ready(function() {
  $.getJSON("http://www.synergiescanada.org/json/otherpublicationbyid?synid=synergies:bcn.arbutus.215.3263" , 
    function(json) {
    alert(json);
  });
</script> 

弹出警报永远不会被触发,据我所知,当 getJSON 检索我的 JSON 数据时出现一些错误后,它会默默地失败。

我尝试使用 firebug 进行调试 我刚刚在控制台中找到了关于标题的信息

(抱歉,我可以添加我是新的图像)

Response Headersview source
Date    Thu, 14 Apr 2011 20:24:49 GMT
X-Powered-By    PHP/5.3.5
Cache-Control   store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Disposition inline; filename=author.json
Last-Modified   Thu, 14 Apr 2011 20:24:49 GMT
Content-Type    application/json
Set-Cookie  SESS65d098c5115a6dff636c637d3c170001=c82ctlcfe0926dr45jrge1crf5; expires=Sat, 07-May-2011 23:58:09 GMT; path=/; domain=www.synergiescanada.org
Expires Sun, 19 Nov 1978 05:00:00 GMT
Connection  keep-alive, timeout=50, maxreq=60
Transfer-Encoding   chunked

Request Headersview source
Host    www.synergiescanada.org
User-Agent  Mozilla/5.0 (X11; U; Linux x86_64; en-CA; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16
Accept  application/json, text/javascript, */*; q=0.01
Accept-Language fr-ca,fr;q=0.8,en-ca;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://localhost/test/ajax.html
Origin  http://localhost

相同的演示页面触发来自 flickr 的 JSON api 并且它根本不抱怨,所以它看起来像我想念的这里有东西。也许这是显而易见的。

如果有人能给我一个线索,我将不胜感激。

I try to retrieve data from a JSon services but I have some problem and I'm not able to pass trough the debug process.

I retrieve data from this dynamique services : http://www.synergiescanada.org/json/otherpublicationbyid?synid=synergies:bcn.arbutus.215.3263 I validate the result with this tool http://jsonformatter.curiousconcept.com/ and it look fine.

[
   {
      "name":"Dr. Andre Smith",
      "publications":[
         {
            "id":"synergies:bcn.arbutus.215.3264",
            "title":"Exploring death and dying through discourse",
            "uri":"http:\/\/journals.uvic.ca\/index.php\/arbutus\/article\/view\/3264",
            "date":"2010-10-18"
         }
      ]
   }
]

But in another way when I use .getJSON method from jquery the it fail.

<script type="text/javascript"> 
$(document).ready(function() {
  $.getJSON("http://www.synergiescanada.org/json/otherpublicationbyid?synid=synergies:bcn.arbutus.215.3263" , 
    function(json) {
    alert(json);
  });
</script> 

The popup alert is never trigged and as I understand getJSON fail silently after having some king of error when he retrive my JSON data.

I try do debug with firebug I just found this into the Console about the headers

(sorry I can add image I'm new)

Response Headersview source
Date    Thu, 14 Apr 2011 20:24:49 GMT
X-Powered-By    PHP/5.3.5
Cache-Control   store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Disposition inline; filename=author.json
Last-Modified   Thu, 14 Apr 2011 20:24:49 GMT
Content-Type    application/json
Set-Cookie  SESS65d098c5115a6dff636c637d3c170001=c82ctlcfe0926dr45jrge1crf5; expires=Sat, 07-May-2011 23:58:09 GMT; path=/; domain=www.synergiescanada.org
Expires Sun, 19 Nov 1978 05:00:00 GMT
Connection  keep-alive, timeout=50, maxreq=60
Transfer-Encoding   chunked

Request Headersview source
Host    www.synergiescanada.org
User-Agent  Mozilla/5.0 (X11; U; Linux x86_64; en-CA; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16
Accept  application/json, text/javascript, */*; q=0.01
Accept-Language fr-ca,fr;q=0.8,en-ca;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
Referer http://localhost/test/ajax.html
Origin  http://localhost

The same demo page trigger JSON api from flickr and it doesn't complain at all so it look as I miss something here. Maybe it's obvious.

If someone can give me a clue I'll appreciate.

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

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

发布评论

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

评论(1

情愿 2024-11-08 22:43:45

看起来像是跨站点脚本问题 - 您试图从外部站点的本地主机获取数据。解决方法可能是使用 PHP 作为“代理”。请参阅: http://jquery-howto .blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

Looks like a cross-site scripting issue -- your trying to get data from localhost of an external site. A workaround could be to use PHP as a "proxy." See: http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

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