HUKD API - 的getJSON REST调用 [英] HUKD API - getJSON Rest call
问题描述
我是新来的JSON和API(一切都像那个)。
我想在英国热卖优惠( HTTP考出了API://www.hotukdeals。 COM / REST的API ),为未来的发展。
我有一个API密钥,并想从热凭证检索数据。
<一个href=\"http://api.hotukdeals.com/rest_api/v2/?key=xxxxxxxxxxx&order=hot&forum=vouchers&results_per_page=5\" rel=\"nofollow\">http://api.hotukdeals.com/rest_api/v2/?key=xxxxxxxxxxx&order=hot&forum=vouchers&results_per_page=5
现在我只想选择一个并显示它。我甚至不能做到这一点,我不知道这是否是我做错了还是什么东西。
现在,这里是我JS code:
<$p$p><$c$c>$.getJSON('http://api.hotukdeals.com/rest_api/v2/?key=xxxxxxxxx&order=hot&forum=vouchers&results_per_page=5&output=json',function(hot){ $('#DIV数据)。HTML(hot.title) }); //结束JSON现在有人说之前,我没有尝试过;我有!我曾尝试不同的方法来获得成交的称号。但我不能得到任何输出。
该API仅支持JSON ANS XML,没有JSONP。这意味着你不能使用JavaScript,以消耗其因相同来源的限制。从浏览器的AJAX发送到不同的域禁止。基本上有两种解决这个限制:
- JSONP (不幸的是需要服务器来支持它,这似乎并没有被您正在试图消耗)的API 的情况下
- 使用您的域名服务器端脚本,将充当桥梁和发送AJAX请求到脚本。
I'm new to JSON and APIs (everything like that).
I am trying to test out the API over at Hot UK Deals (http://www.hotukdeals.com/rest-api), for a future development.
I have an API key and would like to retrieve data from the hot vouchers.
http://api.hotukdeals.com/rest_api/v2/?key=xxxxxxxxxxx&order=hot&forum=vouchers&results_per_page=5
Now I want to just select one and display it. I can't even do that, I'm not sure if it's something that I'm doing wrong or what.
Now here's my JS code:
$.getJSON('http://api.hotukdeals.com/rest_api/v2/?key=xxxxxxxxx&order=hot&forum=vouchers&results_per_page=5&output=json',function(hot){
$('div#data').html(hot.title)
});//end JSON
Now before someone says, that I haven't tried; I have! I have tried different ways to get the title of a deal. But I can't get any output.
The API only supports JSON ans XML, not JSONP. This means that you cannot use javascript in order to consume it due to the same origin policy restriction. Browsers forbid from sending AJAX to different domains. Basically there are two workarounds for this restriction:
- JSONP (which unfortunately requires the server to support it, which doesn't seem to be the case for the API you are trying to consume)
- Use a server side script on your domain that will act as a bridge and send the AJAX request to your script.
这篇关于HUKD API - 的getJSON REST调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!