开发者

Remote JSONP datasource isn't working for me

no matter what i do, i couldn't get alert("test"); to display an alert. for some reason this jsonp (although it fetches the data correctly: http://u.kodingen.com/1JsHcN ) never calls the success function.

if i copy and paste the example here: http://jqueryui.com/demos/autocomplete/#remote-jsonp it works beautifully. but my URL doesn't.

any ideas?

        $("#venue_in").au开发者_开发百科tocomplete({
        source: function(request, response) {
            $.ajax({
                url: "http://x.com/y.php",
                dataType: "jsonp",
                data: request,
                cache: false,                
                success: function(data) {
                    alert("test");
                    response(data);
                }
            })
        },
        minLength: 2,
    });


Your URL doesn't seem to be returning valid JSONP. It's not the same as JSON.

if your regular JSON url (http://x.com/y.php) returns JSON like this:

[{'label':'blah blah','value':3},{'label':'foo",'value':42}]

then the same JSONP url would look something like this:

`http://x.com/y.php?callback=myfunc`

and it would return something like this:

myfunc([{'label':'blah blah','value':3},{'label':'foo",'value':42}])

Your url dosn't appear to be including the 'P' part of JSONP.

wikipedia's page isn't super-clear, but if you scroll down to the part on JSONP, and then read it carefully, it should make sense. (If anyone has a better reference than wikipedia, please post it).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜