views:

28

answers:

1

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").autocomplete({
        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,
    });
+1  A: 

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).

Lee
isn't that $.ajax's job to parse that into an arbitrary jsonp1234567 kind of callback function and get that as 'data' in success: function(data)?
Devrim
oh ok i see it now... http://u.kodingen.com/1Jtf94 - thx for the answer!
Devrim