[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-30 Thread Stefano Corallo


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=hackdayindialang=en-usformat=jsoncallback=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!


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-30 Thread Ricardo Tomasi

We can't access the success function of the $.ajax call without
messing with jQuery source code, because the vars that name it are
inside the jQuery function scope.

In JSONP, the JSON object is passed as an argument to the callback
function. In the example I posted:

jsonFlickrFeed = function(data){ //do something with data };

On Jan 30, 7:28 am, Stefano Corallo stefan...@gmail.com wrote:
 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=hackdayindialang=en-usformat=jsoncallback=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!


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-30 Thread Stefano Corallo


On 30 Gen, 19:25, Ricardo Tomasi ricardob...@gmail.com wrote:
 We can't access the success function of the $.ajax call without
 messing with jQuery source code, because the vars that name it are
 inside the jQuery function scope.


ok

 In JSONP, the JSON object is passed as an argument to the callback
 function. In the example I posted:

 jsonFlickrFeed = function(data){ //do something with data };


i've tried but data is always undefined,take a look:

http://jsbin.com/ajimu/edit

 On Jan 30, 7:28 am, Stefano Corallo stefan...@gmail.com wrote:

  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=hackdayindialang=en-usformat=jsoncallback=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!


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-30 Thread Ricardo Tomasi

Ah, an oversight of mine. I forgot to add the parameter when rewriting
the callback.

Fixed as you can see at http://jsbin.com/eliwu

Never use someone else's code without inspection ;)

On Jan 30, 4:34 pm, Stefano Corallo stefan...@gmail.com wrote:
 On 30 Gen, 19:25, Ricardo Tomasi ricardob...@gmail.com wrote:

  We can't access the success function of the $.ajax call without
  messing with jQuery source code, because the vars that name it are
  inside the jQuery function scope.

 ok

  In JSONP, the JSON object is passed as an argument to the callback
  function. In the example I posted:

  jsonFlickrFeed = function(data){ //do something with data };

 i've tried but data is always undefined,take a look:

 http://jsbin.com/ajimu/edit

  On Jan 30, 7:28 am, Stefano Corallo stefan...@gmail.com wrote:

   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=hackdayindialang=en-usformat=jsoncallback=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!


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-30 Thread Stefano Corallo

:) in effect i've investigated but i'm not a guru of js so i need some
help ... thanks.

last but not least :D can you explain this code:

self[callback] = window[callback];
  window[callback] = (function(callback){
return function(data){
   (window[callback] = self[callback])(data);
delete self[callback];
clearTimeout(timer);
   };
  })(callback);

On 30 Gen, 23:57, Ricardo Tomasi ricardob...@gmail.com wrote:
 Ah, an oversight of mine. I forgot to add the parameter when rewriting
 the callback.

 Fixed as you can see athttp://jsbin.com/eliwu

 Never use someone else's code without inspection ;)

 On Jan 30, 4:34 pm, Stefano Corallo stefan...@gmail.com wrote:

  On 30 Gen, 19:25, Ricardo Tomasi ricardob...@gmail.com wrote:

   We can't access the success function of the $.ajax call without
   messing with jQuery source code, because the vars that name it are
   inside the jQuery function scope.

  ok

   In JSONP, the JSON object is passed as an argument to the callback
   function. In the example I posted:

   jsonFlickrFeed = function(data){ //do something with data };

  i've tried but data is always undefined,take a look:

 http://jsbin.com/ajimu/edit

   On Jan 30, 7:28 am, Stefano Corallo stefan...@gmail.com wrote:

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=hackdayindialang=en-usformat=jsoncallback=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!


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-30 Thread Ricardo Tomasi

That's a closure to save the 'callback' variable in it's own scope.
Actually it's not needed :)

The way that works is we create an anonymous function that will run
immediately, accepting as a parameter the callback name, and then
return a function which will be assigned to window[callback];

Like

myFunctionWithBeef = (function(x){
   //'beef' is available in here in the var 'x';
   return function(){...}; //this function will be stored in the
'myFunctionWithBeef' variable, and will have access to all vars in
this scope
})('beef');

Here is how it looks without it:

  self.timeout = function(){
if (self[callback]){
  window[callback] = function(){};
  s.onTimeout(s.url);
  $('head script[src$='+s.url+']').remove();
  delete self[callback];
};
};

The function is already declared in the scope where 'callback' is
available, so that closure is unnecessary. I think I left it that way
because it was originally inside a timeout, which runs in the global
scope.

One thing you must be aware of is that this script will not allow two
consecutive ajax calls with the same callback function, 'cause one
will overwrite the other.

cheers,
- ricardo

On 30 jan, 22:14, Stefano Corallo stefan...@gmail.com wrote:
 :) in effect i've investigated but i'm not a guru of js so i need some
 help ... thanks.

 last but not least :D can you explain this code:

 self[callback] = window[callback];
   window[callback] = (function(callback){
     return function(data){
        (window[callback] = self[callback])(data);
         delete self[callback];
         clearTimeout(timer);
    };
   })(callback);

 On 30 Gen, 23:57, Ricardo Tomasi ricardob...@gmail.com wrote:

  Ah, an oversight of mine. I forgot to add the parameter when rewriting
  the callback.

  Fixed as you can see athttp://jsbin.com/eliwu

  Never use someone else's code without inspection ;)

  On Jan 30, 4:34 pm, Stefano Corallo stefan...@gmail.com wrote:

   On 30 Gen, 19:25, Ricardo Tomasi ricardob...@gmail.com wrote:

We can't access the success function of the $.ajax call without
messing with jQuery source code, because the vars that name it are
inside the jQuery function scope.

   ok

In JSONP, the JSON object is passed as an argument to the callback
function. In the example I posted:

jsonFlickrFeed = function(data){ //do something with data };

   i've tried but data is always undefined,take a look:

  http://jsbin.com/ajimu/edit

On Jan 30, 7:28 am, Stefano Corallo stefan...@gmail.com wrote:

 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 

[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-28 Thread Stefano Corallo

thank's i'll give it a try ... stay tuned :D

On 27 Gen, 22:45, Ricardo Tomasi ricardob...@gmail.com wrote:
 Hi Stefano, I think I found a solution. All you need to do is check if
 the callback has been called after your specified timeout. If it has
 not been called yet, overwrite it with an empty function, else do
 nothing. That will mess up with any further usage of the callback, but
 it works for this case anyway, take a look:

 http://jsbin.com/ukehu/http://jsbin.com/ukehu/edit

 Change the timeout: 1 in the $.jsonp() call to a short/long value to
 test it. I made the callback and timeout callback Firebug logs also.

 cheers,
 - ricardo

 On Jan 27, 5:01 pm, Ricardo Tomasi ricardob...@gmail.com wrote:

  Unless you remove the script tag after the 'timeout', of couse.

  On Jan 27, 9:59 am, Mike Alsup mal...@gmail.com wrote:

ah  and there is no way to simulate that?

   You can simulate a timeout in your code by using setTimeout, but it's
   not the same as when the XHR is used for the request.  With XHR jQuery
   can invoke the abort fn to cancel the request.  There is no such
   option for the jsonp script injection method.  So you can not close
   the connection or do anything particularly useful other than assume
   your timeout is being called because the request failed.  But then
   you're only guessing, and the response may return the moment after you
   time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-28 Thread Stefano Corallo

Ok perfect :) Many thanks.

So if i've understand the request continue loading and when server
send back the response (if any) if the timeout as occured there is no
callback set on window and do nothing else do the job  have any
sense try to shutdown the request? Is possible?

Anyway thanks a lot.

On 28 Gen, 09:23, Stefano Corallo stefan...@gmail.com wrote:
 thank's i'll give it a try ... stay tuned :D

 On 27 Gen, 22:45, Ricardo Tomasi ricardob...@gmail.com wrote:

  Hi Stefano, I think I found a solution. All you need to do is check if
  the callback has been called after your specified timeout. If it has
  not been called yet, overwrite it with an empty function, else do
  nothing. That will mess up with any further usage of the callback, but
  it works for this case anyway, take a look:

 http://jsbin.com/ukehu/http://jsbin.com/ukehu/edit

  Change the timeout: 1 in the $.jsonp() call to a short/long value to
  test it. I made the callback and timeout callback Firebug logs also.

  cheers,
  - ricardo

  On Jan 27, 5:01 pm, Ricardo Tomasi ricardob...@gmail.com wrote:

   Unless you remove the script tag after the 'timeout', of couse.

   On Jan 27, 9:59 am, Mike Alsup mal...@gmail.com wrote:

 ah  and there is no way to simulate that?

You can simulate a timeout in your code by using setTimeout, but it's
not the same as when the XHR is used for the request.  With XHR jQuery
can invoke the abort fn to cancel the request.  There is no such
option for the jsonp script injection method.  So you can not close
the connection or do anything particularly useful other than assume
your timeout is being called because the request failed.  But then
you're only guessing, and the response may return the moment after you
time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-28 Thread Stefano Corallo

Hi Riccardo,

i've a problem in the example you posted you do:

$.jsonp({
  url: 'http://api.flickr.com/services/feeds/photos_public.gne?
tags=hackdayindialang=en-usformat=jsoncallback=jsonFlickrFeed',
  timeout: 1,
  onTimeout: function(url){ console.error('jsonp script timed out:
'+url) }
});

how about the success function? and the error one etc etc ?!?!

I'm tring to something like this :

.jsonp({
   type: GET,
   url: some.php,
   data: name=Johnlocation=Boston,
   timeout: 1, // in seconds
   success: function(msg){
 alert( Data Saved:  + msg );
   },
   error:function(request, errorType, errorThrown){
  alert(oppps  );
   },
   onTimeout:function(url){ console.error('jsonp script timed out:
'+url) }
 });

the success function is never executed (timeout or not).
In your example you've defined a function before the $.jsonp call (the
jsonFlickrFeed) and added in the url of the request ... why the
success function is not working? I've forgotten something?

Thanks.

On 28 Gen, 10:15, Stefano Corallo stefan...@gmail.com wrote:
 Ok perfect :) Many thanks.

 So if i've understand the request continue loading and when server
 send back the response (if any) if the timeout as occured there is no
 callback set on window and do nothing else do the job  have any
 sense try to shutdown the request? Is possible?

 Anyway thanks a lot.

 On 28 Gen, 09:23, Stefano Corallo stefan...@gmail.com wrote:

  thank's i'll give it a try ... stay tuned :D

  On 27 Gen, 22:45, Ricardo Tomasi ricardob...@gmail.com wrote:

   Hi Stefano, I think I found a solution. All you need to do is check if
   the callback has been called after your specified timeout. If it has
   not been called yet, overwrite it with an empty function, else do
   nothing. That will mess up with any further usage of the callback, but
   it works for this case anyway, take a look:

  http://jsbin.com/ukehu/http://jsbin.com/ukehu/edit

   Change the timeout: 1 in the $.jsonp() call to a short/long value to
   test it. I made the callback and timeout callback Firebug logs also.

   cheers,
   - ricardo

   On Jan 27, 5:01 pm, Ricardo Tomasi ricardob...@gmail.com wrote:

Unless you remove the script tag after the 'timeout', of couse.

On Jan 27, 9:59 am, Mike Alsup mal...@gmail.com wrote:

  ah  and there is no way to simulate that?

 You can simulate a timeout in your code by using setTimeout, but it's
 not the same as when the XHR is used for the request.  With XHR jQuery
 can invoke the abort fn to cancel the request.  There is no such
 option for the jsonp script injection method.  So you can not close
 the connection or do anything particularly useful other than assume
 your timeout is being called because the request failed.  But then
 you're only guessing, and the response may return the moment after you
 time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-28 Thread Ricardo Tomasi

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.

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

cheers,
- ricardo

On Jan 28, 10:07 am, Stefano Corallo stefan...@gmail.com wrote:
 Hi Riccardo,

 i've a problem in the example you posted you do:

 $.jsonp({
   url: 'http://api.flickr.com/services/feeds/photos_public.gne?
 tags=hackdayindialang=en-usformat=jsoncallback=jsonFlickrFeed',
   timeout: 1,
   onTimeout: function(url){ console.error('jsonp script timed out:
 '+url) }

 });

 how about the success function? and the error one etc etc ?!?!

 I'm tring to something like this :

 .jsonp({
    type: GET,
    url: some.php,
    data: name=Johnlocation=Boston,
    timeout: 1, // in seconds
    success: function(msg){
      alert( Data Saved:  + msg );
    },
    error:function(request, errorType, errorThrown){
       alert(oppps  );
    },
    onTimeout:function(url){ console.error('jsonp script timed out:
 '+url) }
  });

 the success function is never executed (timeout or not).
 In your example you've defined a function before the $.jsonp call (the
 jsonFlickrFeed) and added in the url of the request ... why the
 success function is not working? I've forgotten something?

 Thanks.

 On 28 Gen, 10:15, Stefano Corallo stefan...@gmail.com wrote:

  Ok perfect :) Many thanks.

  So if i've understand the request continue loading and when server
  send back the response (if any) if the timeout as occured there is no
  callback set on window and do nothing else do the job  have any
  sense try to shutdown the request? Is possible?

  Anyway thanks a lot.

  On 28 Gen, 09:23, Stefano Corallo stefan...@gmail.com wrote:

   thank's i'll give it a try ... stay tuned :D

   On 27 Gen, 22:45, Ricardo Tomasi ricardob...@gmail.com wrote:

Hi Stefano, I think I found a solution. All you need to do is check if
the callback has been called after your specified timeout. If it has
not been called yet, overwrite it with an empty function, else do
nothing. That will mess up with any further usage of the callback, but
it works for this case anyway, take a look:

   http://jsbin.com/ukehu/http://jsbin.com/ukehu/edit

Change the timeout: 1 in the $.jsonp() call to a short/long value to
test it. I made the callback and timeout callback Firebug logs also.

cheers,
- ricardo

On Jan 27, 5:01 pm, Ricardo Tomasi ricardob...@gmail.com wrote:

 Unless you remove the script tag after the 'timeout', of couse.

 On Jan 27, 9:59 am, Mike Alsup mal...@gmail.com wrote:

   ah  and there is no way to simulate that?

  You can simulate a timeout in your code by using setTimeout, but 
  it's
  not the same as when the XHR is used for the request.  With XHR 
  jQuery
  can invoke the abort fn to cancel the request.  There is no such
  option for the jsonp script injection method.  So you can not close
  the connection or do anything particularly useful other than assume
  your timeout is being called because the request failed.  But then
  you're only guessing, and the response may return the moment after 
  you
  time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Mike Alsup


 In this case the execution stop because the return statement and there
 is no way to setup the onreadystatefunction and other stuff coded down
 after the statement

 if ( s.dataType == script  type == GET  parts
                          ( parts[1]  parts[1] != location.protocol || 
 parts[2] !=
 location.host )){

 This in my case generate a non correct handling of the timeout lookup
 but maybe there are other problem i'm not able to see.

 Thank's for help and clarifications.


This is because ajax can not be used x-domain due to browser security.

http://docs.jquery.com/Ajax/jQuery.ajax#options


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Stefano Corallo

yes ok but i've set the jsonp option to avoid this problem like
explained in

http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

that i've found http://docs.jquery.com/Ajax/jQuery.ajax#options

i'm wrong?


On 27 Gen, 12:06, Mike Alsup mal...@gmail.com wrote:
  In this case the execution stop because the return statement and there
  is no way to setup the onreadystatefunction and other stuff coded down
  after the statement

  if ( s.dataType == script  type == GET  parts
                           ( parts[1]  parts[1] != location.protocol || 
  parts[2] !=
  location.host )){

  This in my case generate a non correct handling of the timeout lookup
  but maybe there are other problem i'm not able to see.

  Thank's for help and clarifications.

 This is because ajax can not be used x-domain due to browser security.

 http://docs.jquery.com/Ajax/jQuery.ajax#options


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Stefano Corallo

With the jsonp option i'm able to do cross domain request but i can't
control the timeout and i'm wondering about why?

On 27 Gen, 12:22, Stefano Corallo stefan...@gmail.com wrote:
 yes ok but i've set the jsonp option to avoid this problem like
 explained in

 http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

 that i've foundhttp://docs.jquery.com/Ajax/jQuery.ajax#options

 i'm wrong?

 On 27 Gen, 12:06, Mike Alsup mal...@gmail.com wrote:

   In this case the execution stop because the return statement and there
   is no way to setup the onreadystatefunction and other stuff coded down
   after the statement

   if ( s.dataType == script  type == GET  parts
                            ( parts[1]  parts[1] != location.protocol || 
   parts[2] !=
   location.host )){

   This in my case generate a non correct handling of the timeout lookup
   but maybe there are other problem i'm not able to see.

   Thank's for help and clarifications.

  This is because ajax can not be used x-domain due to browser security.

 http://docs.jquery.com/Ajax/jQuery.ajax#options


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Mike Alsup

 With the jsonp option i'm able to do cross domain request but i can't
 control the timeout and i'm wondering about why?

 On 27 Gen, 12:22, Stefano Corallo stefan...@gmail.com wrote:

  yes ok but i've set the jsonp option to avoid this problem like
  explained in

 http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

  that i've foundhttp://docs.jquery.com/Ajax/jQuery.ajax#options


This is because ajax is not being used.  There are no readystatechange
callbacks and there is no way to cancel an outstanding jsonp request.
In other words, there is no way to reliably implement timeout.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Stefano Corallo

ah  and there is no way to simulate that?

i want close the connection with the server if the request take a
long time, and do something default like a message or other stuff ...
what can i do?

On 27 Gen, 12:30, Mike Alsup mal...@gmail.com wrote:
  With the jsonp option i'm able to do cross domain request but i can't
  control the timeout and i'm wondering about why?

  On 27 Gen, 12:22, Stefano Corallo stefan...@gmail.com wrote:

   yes ok but i've set the jsonp option to avoid this problem like
   explained in

  http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

   that i've foundhttp://docs.jquery.com/Ajax/jQuery.ajax#options

 This is because ajax is not being used.  There are no readystatechange
 callbacks and there is no way to cancel an outstanding jsonp request.
 In other words, there is no way to reliably implement timeout.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Mike Alsup

 ah  and there is no way to simulate that?

You can simulate a timeout in your code by using setTimeout, but it's
not the same as when the XHR is used for the request.  With XHR jQuery
can invoke the abort fn to cancel the request.  There is no such
option for the jsonp script injection method.  So you can not close
the connection or do anything particularly useful other than assume
your timeout is being called because the request failed.  But then
you're only guessing, and the response may return the moment after you
time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Ricardo Tomasi

Unless you remove the script tag after the 'timeout', of couse.

On Jan 27, 9:59 am, Mike Alsup mal...@gmail.com wrote:
  ah  and there is no way to simulate that?

 You can simulate a timeout in your code by using setTimeout, but it's
 not the same as when the XHR is used for the request.  With XHR jQuery
 can invoke the abort fn to cancel the request.  There is no such
 option for the jsonp script injection method.  So you can not close
 the connection or do anything particularly useful other than assume
 your timeout is being called because the request failed.  But then
 you're only guessing, and the response may return the moment after you
 time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Ricardo Tomasi

Hi Stefano, I think I found a solution. All you need to do is check if
the callback has been called after your specified timeout. If it has
not been called yet, overwrite it with an empty function, else do
nothing. That will mess up with any further usage of the callback, but
it works for this case anyway, take a look:

http://jsbin.com/ukehu/
http://jsbin.com/ukehu/edit

Change the timeout: 1 in the $.jsonp() call to a short/long value to
test it. I made the callback and timeout callback Firebug logs also.

cheers,
- ricardo

On Jan 27, 5:01 pm, Ricardo Tomasi ricardob...@gmail.com wrote:
 Unless you remove the script tag after the 'timeout', of couse.

 On Jan 27, 9:59 am, Mike Alsup mal...@gmail.com wrote:

   ah  and there is no way to simulate that?

  You can simulate a timeout in your code by using setTimeout, but it's
  not the same as when the XHR is used for the request.  With XHR jQuery
  can invoke the abort fn to cancel the request.  There is no such
  option for the jsonp script injection method.  So you can not close
  the connection or do anything particularly useful other than assume
  your timeout is being called because the request failed.  But then
  you're only guessing, and the response may return the moment after you
  time it out.


[jQuery] Re: $.ajax bug ?!? Maybe i've not understand somethings ....

2009-01-27 Thread Mike Alsup

 Hi Stefano, I think I found a solution. All you need to do is check if
 the callback has been called after your specified timeout. If it has
 not been called yet, overwrite it with an empty function, else do
 nothing. That will mess up with any further usage of the callback, but
 it works for this case anyway, take a look:


Cool idea, Ricardo.  :-)