0

外部ドメインに次の JSON 形式のファイルがあります。

{"image":"http:\/\/magazine.domain.com\/wp-content\/uploads\/2013\/06\/festival_home-240x122.jpg","link":"http:\/\/magazine.domain.com\/category\/fashion\/forget-the-mud-festival-fashion-essentials\/","title":"FESTIVAL FASHION ESSENTIALS","description":"What to wear at festivals is a perennial problem for music lovers, follow our fashion guide and be the best dressed moshing in the mud this summer!"}

JSONP を使用してデータを取得する必要があり、形式を次のように変更しました。

jsonCallback ({"image":"http:\/\/magazine.domain.com\/wp-content\/uploads\/2013\/06\/festival_home-240x122.jpg","link":"http:\/\/magazine.domain.com\/category\/fashion\/forget-the-mud-festival-fashion-essentials\/","title":"FESTIVAL FASHION ESSENTIALS","description":"What to wear at festivals is a perennial problem for music lovers, follow our fashion guide and be the best dressed moshing in the mud this summer!"});

私はjquery 1.3.2を使用していますが、現時点ではこれをアップグレードできず、次のことを試しました:

var url='http://magazine.domain.com/test1.js?callback=?';

$.getJSON(url, function(data){
 console.log(data);
});

次のエラーが表示されます - Uncaught ReferenceError: jsonCallback is not defined.

誰か助けてください。

4

2 に答える 2

0
var url='http://magazine.domain.com/test1.js';

$.ajax({
    url: url,
    dataType: 'jsonp', // <-- jsonp
    success: function(resp) {
        // resp == {"image":"http:\/\/magazine.domain.com\/wp-content\/uploads\/2013\/06\/festival_home-240x122.jpg","link":"http:\/\/magazine.domain.com\/category\/fashion\/forget-the-mud-festival-fashion-essentials\/","title":"FESTIVAL FASHION ESSENTIALS","description":"What to wear at festivals is a perennial problem for music lovers, follow our fashion guide and be the best dressed moshing in the mud this summer!"}
    }
});
于 2013-06-07T14:14:32.910 に答える
0

クエリ文字列パラメーターjsonCallbackの値に置き換える必要があります。callback

于 2013-06-07T14:13:07.333 に答える