微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

$ .getJSON检索数据时出现静默错误

如何解决$ .getJSON检索数据时出现静默错误

| 我尝试从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,它一点也没有抱怨,所以我在这里错过了一些东西。也许很明显。 如果有人可以给我一个提示,我将不胜感激。     

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。