简体   繁体   English

跨域请求的GetJSON

[英]GetJSON for crossdomain request

I'm trying to collect some data from an opendata service. 我正在尝试从开放数据服务中收集一些数据。 i'm stuck with my jquery request, folowing the example from Jquery documentation which use the flicker API, it works. 我坚持我的jquery请求,按照Jquery文档中使用flicker API的示例进行操作,它可以正常工作。 But when I changed the URL, I don't get the callback action played (here an alert popup). 但是,当我更改URL时,没有播放回叫操作(在此弹出警报)。 I can see in the Chrome console that the request is played and the correct result returns, but no action is performed in my callback. 我可以在Chrome控制台中看到播放了请求,并返回了正确的结果,但是在回调中未执行任何操作。

Here is my test : 这是我的测试:

     <html>
     <body>
     <h1>Hello, world!</h1>
     <script src="http://code.jquery.com/jquery-latest.js"></script>
     <span id="info"></span>
     <script>  
       $.getJSON("https://open.tan.fr/ewp/tempsattente.json/SECH?jsoncallback=?",
       {},
     function(data) {
              alert("foo");
     });
     </script>
     </body>
     </html>

Can someone tell me why it don't to works? 有人可以告诉我为什么它不起作用吗? any suggestion ? 有什么建议吗? Thanks. 谢谢。

If you use .error on the getJSON method, you can find out why it failed (hopefully). 如果在getJSON方法上使用.error ,则可以找出失败的原因(希望如此)。 Since you said you seem to be getting the correct response and it "works", it makes sense that it's a parsing error (basically all that's left after a 200 is received). 既然您说过您似乎得到了正确的响应并且它“有效”,那么这是解析错误(基本上是收到200后剩下的所有内容),这是有道理的。 If you use .error , you find this message: 如果使用.error ,则会发现以下消息:

Error: jQuery18206930075496322584_1355933072137 was not called

and in a different place, find it was because of a 在另一个地方,发现是因为

parsererror

^ http://jsfiddle.net/dCTES/ ^ http://jsfiddle.net/dCTES/

If you take the actual response and run it through JSON.parse , it says: 如果您获取实际的响应并通过JSON.parse运行它,它将显示:

SyntaxError: JSON.parse: unexpected character

And it is pointing to the value: 它指向值:

"Fran\u00e7ois Mitterrand"

^ http://jsfiddle.net/dCTES/1/ ^ http://jsfiddle.net/dCTES/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM