On 28 Gen, 17:03, Ricardo Tomasi <ricardob...@gmail.com> wrote:
> It isn't possible to have error/success callbacks for JSONP. You can't
> cancel the request either. Once you add a <script> tag to the head,
> the browser fires a GET request and it can't be interrupted - even if
> you remove the script before the response comes, the script will still
> run.
>

ok. got it!

> (the only event that fires on the script tag is 'onload', but it only
> tells you if the content has successfully loaded, not the opposite.
> There is no way to know if an error happened)
>
> Also, you're misunderstanding the way JSONP works - there is no need
> for a 'success' function, that is the callback function which will be
> called when the response is loaded. Thats 'jsonFlickerFeed' in my
> example.
>

Ok i've understood how jsonp work, but there's something that i can't
understand.
I try to explain better i can (sorry for my bad english)

1)Using the $.ajax method, an example:
$.ajax({
                           type: methodType,
                           url: theURL,
                           data: params,
                           dataType:"jsonp",
                           success: function(data){
                                        console.log("onClick success");
                                   }
                            });

in the jquery core is built a temporary jsonp function to handle the
data returned by the server, if the succes function is defined the
temporary function call the succe function and pass the returned
data ... specifically at line 3314 of the jquery.1.3.1.js :

// Handle JSONP-style loading
                        window[ jsonp ] = function(tmp){
                                data = tmp;
                                success();
                                complete();
                                // Garbage collect
                                window[ jsonp ] = undefined;
                                try{ delete window[ jsonp ]; } catch(e){}
                                if ( head )
                                        head.removeChild( script );
                        };

the tmp is the data returned by the server.

Now in your example you use the jsonFlickrFeed function but without
handling the returned data from the server:

jsonFlickrFeed = function(){ alert('flickr loaded'); };
$.jsonp({
  url: 'http://api.flickr.com/services/feeds/photos_public.gne?
tags=hackdayindia&lang=en-us&format=json&callback=jsonFlickrFeed',
  timeout: 10,
  onTimeout: function(url){ console.error('jsonp script timed out:
'+url) }
});

how to access the data returned from the server? How to modify the
$.jsonp function to call the success function defined and pass in the
data returned from the server ... this is sure possible case jquery in
$.ajax call do it, but i don't know how :-/

Many thanks, really!

I hope i've been clear, sorry for my english!

Reply via email to