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

您需要替换jsonCallbackcallback查询字符串参数的值。

于 2013-06-07T14:13:07.333 回答
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 回答