如何查询带有jQuery的Best Buy Remix API? [英] How can I query the Best Buy Remix API w/ jQuery?
问题描述
以下是我一直尝试使用的代码:
Here's the code that I've been trying to work with:
$.getJSON("http://api.remix.bestbuy.com/v1/products(search=" + escape(searchCriteria) + ")?apiKey=" + hhApiKey + "&format=json&callback=?",
function(data) {
if(data.error) {
alert("I'm sorry, there was an error processing your request.");
} else {
alert(data);
}
});
但是,返回的数据有一个错误,因为它不理解所请求的URL.我查看了Firebug中的net标签,这是它试图调用的URL:
However, the data that comes back has an error because it doesn't understand the requested URL. I looked at the net tab in Firebug and here's the URL it's trying to call out to:
http://api.remix.bestbuy.com/v1/products(search=digital%20camera)?apiKey=myapikey&format=json&callback=json1264868431 & _1254866270659 =
我认为问题在于粗体部分,据我所知,该部分无缘无故地被添加.我认为Remix API可以看到它,并且认为它是错误的参数.有什么办法可以阻止它被添加?
I think the problem lays in the bolded section which is being added on for no reason as far as I can tell. I think the Remix API sees it and thinks it's a botched parameter. Is there any way to stop that from being added?
推荐答案
在禁用jQuery ajax的缓存设置时,它将尝试将时间戳添加到查询字符串.这可能是您遇到的问题.尝试在显式启用缓存的情况下调用该函数.
When disabling the cache setting for jQuery ajax it will attempt to append a timestamp to the querystring. This may be the problem your experiencing. Try calling the function with caching explicitly enabled.
$.ajax({
type: "GET",
url: "http://api.remix.bestbuy.com/v1/products(search=" + escape(searchCriteria) + ")?apiKey=" + hhApiKey + "&format=json&callback=?",
cache: true,
success: function() {
alert('success');
},
dataType: 'json'
});
这篇关于如何查询带有jQuery的Best Buy Remix API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!