开发者

jQuery UI AutoComplete with Jsonp source help?

I have my own sample running locally but I cannot get it to hook up with jsonp source data. It works fine with json data.

I looked at the sample here http://jqueryui.com/demos/autocomplete/remote-jsonp.html

If I understand things correctly jsonp returns back string which is includes a call to a js function. In the sample above it doesn't appear to be calling a function upon return. How is that so?

In my sample it returning data which looks like the following and upon its' return it wants to call the js function myfunc.

myfunc([{"results":[
{"id":"0","name":"Leonor"},
{"id":"1","name":"Terry"},
{"id":"2","name":"James"},
{"id":"3","name":"Benjamin"},
{"id":"4","name":"Regina"},
{"id":"5","name":"Debra"}
],"total":"5"}])

With the sample above it is returning data like the following. Notice here however that it is not trying to call a function jQuery15107172246546687473_1305657637754

Why does my code want to call myfunc however the jquery ui sample doesn't call the jQuery15107172246546687473_1305657637754 function?

jQuery15107172开发者_运维百科246546687473_1305657637754({"totalResultsCount":1519,"geonames":[{"alternateNames":[{"name":"Yar","lang":"en"},{"name":"Jar","lang":"no"},{"name":"ЯР","lang":"ru"}],"countryName":"Russia","adminCode1":"80","fclName":"city, village,...","score":28.82040023803711,"countryCode":"RU","lng":52.1052778,"adminName2"
...
,"lat":55.019887,"adminName1":"Novosibirsk","population":0}]});

To be complete I am including the jquery ui sample code view-source:http://jqueryui.com/demos/autocomplete/remote-jsonp.html


Resolved When calling using jsonp format the querystring with include a callback parameter. On the server side it is important to prepend this callback parameter to your json output with this callback parameter.

As in the sample above the dynamically generated callback was jQuery15107172246546687473_1305657637754 so the resolution was to ensure this parameter prepended my json string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜