从谷歌/冰自动完成自定义文件夹。有什么办法来读取收到的JSON文件? [英] Custom box with autocomplete from Google/Bing. Is there any way to read the received json file?
问题描述
我尝试建立一个搜索框的网页。我想利用自动完成选项从兵(例如)。
I try to build a webpage with a search box. I want to take the autocomplete options from Bing (for example).
有可能由冰获取自动完成:
It is possible to get the autocomplete from bing by:
http://api.bing.com/osjson.aspx?query=YOUR_QUERY
我写了一些code时自动完成构件,要求得到JSON作为JSONP,我成功地看到(在小提琴手)的JSON到达。但由于它到达仅作为JSON,而不是在要求的格式,我得到parseError。 (我看见它在错误的功能,成功函数不叫)
I wrote some code with an autocomplete widget, asking to get the json as jsonp, and I succeed to see (in Fiddler) that the json arrives. But because it arrives only as a json, and not in the required format, I get parseError. (I saw it in the error function. The success function is not called)
相关部分从我的code是:
The relevant part from my code is:
$( "#mySesearchBox" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://api.bing.com/osjson.aspx?query=" + request.term,
dataType: "jsonp",
...
有没有办法解决这个问题?
Is there any way to overcome this problem?
我想过运行某些服务器会得到这样的查询,将要求从兵的JSON,并会在需要的格式作出回应。不过,我preFER更简单的解决方案。
I thought about running some server that will get such a query, will ask for the json from Bing and will respond in the required format. However, I prefer more simple solution.
任何意见?
推荐答案
一个工作演示全:的http://的jsfiddle。净/ LxXJz /
本用途: http://api.bing.net/qson.aspx
的或的
在这里你去测试像这样的演示: http://jsfiddle.net/ zNUBc /
Here you go "test" like this Demo : http://jsfiddle.net/zNUBc/
.getJSON
: http://api.jquery.com/jquery.getjson/
轻拂你的整个code,或拨弄我会整理出来给你。)
希望这个演示帮助您
Flick your whole code, or a fiddle I might sort it out for you :)
Hope this demo help you.
code
var url = 'http://api.bing.com/osjson.aspx?JsonType=callback&JsonCallback=?';
$.getJSON(url, {
query: 'hulk'
}, function (data) {
document.write(data)
});
更新16小时后者:)
下面是使用该解决方案: http://api.bing.com/osjson.aspx
Here is the solution using : http://api.bing.com/osjson.aspx
演示=> http://jsfiddle.net/pW6LZ/
仔细看看这个screeshot:
see this screeshot carefully:
这篇关于从谷歌/冰自动完成自定义文件夹。有什么办法来读取收到的JSON文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!