【发布时间】:2012-04-11 15:05:08
【问题描述】:
我正在尝试使用 jQuery.getJSON 调用 ShopSense API (https://shopsense.shopstyle.com/shopsense/7268009frtd4rf) 的 apiSearch 方法,下面是代码。
$(document).ready( function() {
$.getJSON("http://api.shopstyle.com/action/apiSearch?jsoncallback=?",
{
pid: "uid3489-4324817-25",
fts:"red+dress",
min: 0,
count: 10,
format : "json"
}, function(data) {
console.log(data);
$.each(data.products, function(i, product) {
alert(product.name);
});
});
});
它会在 chrome 中导致错误“Uncaught SyntaxError: Unexpected token :”,在 firebug 中导致“invalid label”。
显然,这似乎是解析错误,但是当我尝试使用 jQuery.parseJSON 方法解析其响应 JSON 时,解析没有问题。
请帮我解决这个问题。
解决方案:
最后我通过更改查询中的几个参数来运行我的代码。
使用回调=? jsoncallback=?
格式 = jsonp
【问题讨论】: