jQuery. Using json data on remote server fails
I am working with json data toge开发者_如何学JAVAther with jQuery. It works perfectly fine when using a local json file, but shows just a blank page when using a remote json file from another server (even when using a complete URL from my own server).
This works:
$.getJSON('9.json', function(data) {
Does does not work:
$.getJSON('http://beta.ambadoo.com/users/9.json', function(data) {
Does anyone know how to fix it?
Thanks!
As of jQuery 1.2, you can load JSON data located on another domain if you specify a JSONP callback.
Source: http://docs.jquery.com/Ajax/jQuery.getJSON
The Solution :)
same server, same port. use jsonp.
See this article.
Seems that the magic is doing the '&callback=?'.
Beginning with version 1.2, jQuery has had native support for JSONP calls. You can load JSON data located on another domain if you specify a JSONP callback, which can be done using the following syntax: url?callback=?.
精彩评论