JSONP: how to build an ajax request?

I am trying to work with the JSONP API across domains. This is an example of the returned data:

photos({"marker":{"@attributes":{"id":"30601","latitude":"52.638061","longitude":"-2.117067","feature":"3","caption":"cat","thumbnailSizes":"60|120|150|180|200|250|300|350|400|400|425|450|500|640"}}});

How can I build an Ajax call that uses this data? I keep getting error messages.

This is what I'm trying to do now:

$.ajax({
    url: pm_url,
    data: {},
    type: "get",
    dataType: "jsonp",
    cache: false,
    success: function(data) {
        console.log(data);
    },
    error: function() {
        alert('Sorry, there was a problem getting the photos!');
    }

In Firebug, I see that the data above is being retrieved, but then I see an error message.

What is wrong with the request? (Or data - although it is checked as JSONP.)

UPDATE:

Thanks for the suggestions. I'm trying now:

            var photos = function (data) {
              alert(data);
            };
            $.ajax({
                url: pm_url,
                dataType: 'jsonp',
                jsonpCallback: 'photos',
            });

This, oddly enough, calls up two Firebug URLs:

http://myapi.com/file.jsonp?x=1&y=2?callback=?
http://myapi.com/file.jsonp?x=1&y=2?callback=photos&_=1304982373561

The first URL appears as an error in the console. What am I doing wrong?!

It is possible that the API itself is incorrect (they need the suffix .jsonp and the callback value is ignored, so the function name is fixed), but I was hoping I could get around it.

+3
source share
2

(). jQuery GET- "callback", - , .

, PHP-:

<?php echo $_GET['callback'].'('.json_encode($some_object).');';?>

, jsonp:

jquery1234: jQuery :

function jquery1234(data){return data;}

,

jquery1234({'somevar':'somevalue'});

... jQuery script - , , .

+4

All Articles