[jQuery] Re: Synchronous JSONP

2008-01-09 Thread Scott Trudeau
What about using the success callback of the JSONP call to initiate the
location.href? Something like:

$('a').click(function() {
  var href = $(this).attr('href');
  $.ajax({
url: 'http://example.com/jsonpmethod?callback=?',
dataType: 'jsonp',
success: function(data) {
  // do whatever with json encoded data
  location.href = href;
}
  });
  return false;
});

On Jan 8, 2008 8:06 PM, Glen Lipka [EMAIL PROTECTED] wrote:

 I think my thought process on this was messed up anyway.
 Here is the use situation.  We are using JSONP to send activity on pages
 to avoid cross-site scripting problems.  One of those activities is clicking
 on a link.

 The problem is that the JSONP is asynchronous so that when the link is
 clicked, the page unloads before the JSONP has a chance to do it's thing.

 What is the best way of allowing the JSONP to do it's thing and pause the
 unload of the page long enough for it to work?

 Glen



 On Jan 8, 2008 1:37 PM, Benjamin Sterling 
 [EMAIL PROTECTED] wrote:

  Glen,
  I have never done it, but I say a while back that you can use the
  jQuery.extend method to overwrite a default method.  I will see if I can
  dig that up, but that may point you in the right direction in the mean time.
 
 
 
  On 1/8/08, Glen Lipka [EMAIL PROTECTED] wrote:
  
   Right now in 1.2.1 the JSONP method uses an asynchronous call to do
   it's thing.
   This sometimes causes a problem when we are sending a call about a
   click event on a link.  The page unloads before the JSONP is finished.
  
   Changing it to be optional (async or synchronous) helps fix that
   problem.
  
   Code we used inside jQuery (with a param call to .ajax)
  
   /* If the request is not async, we need to wait for the script to l oad
   before returning. */
   else if (!s.async) {
 var done = false;
 // Attach handlers for all browsers
   script.onload = script.onreadystatechange = function(){
 if ( !done  (!this.readyState ||
   this.readyState == loaded || this.readyState == complete)
   ) {
 }
   };
 }
  
   QUESTION:  Putting this directly into our copy of jQuery is probably a
   bad idea.  *How can this be turned into a plugin?*
  
   Thanks much,
  
   Glen
  
 
 
 
  --
  Benjamin Sterling
  http://www.KenzoMedia.com
  http://www.KenzoHosting.com
  http://www.benjaminsterling.com





-- 
--
Scott Trudeau
scott.trudeau AT gmail DOT com
http://sstrudeau.com/
AIM: sodthestreets


[jQuery] Re: Synchronous JSONP

2008-01-08 Thread Benjamin Sterling
Glen,
I have never done it, but I say a while back that you can use the
jQuery.extend method to overwrite a default method.  I will see if I can dig
that up, but that may point you in the right direction in the mean time.

On 1/8/08, Glen Lipka [EMAIL PROTECTED] wrote:

 Right now in 1.2.1 the JSONP method uses an asynchronous call to do it's
 thing.
 This sometimes causes a problem when we are sending a call about a click
 event on a link.  The page unloads before the JSONP is finished.

 Changing it to be optional (async or synchronous) helps fix that problem.

 Code we used inside jQuery (with a param call to .ajax)

 /* If the request is not async, we need to wait for the script to l oad
 before returning. */
 else if (!s.async) {
   var done = false;
   // Attach handlers for all browsers
 script.onload = script.onreadystatechange = function(){
   if ( !done  (!this.readyState ||
 this.readyState == loaded || this.readyState == complete) ) {
   }
 };
   }

 QUESTION:  Putting this directly into our copy of jQuery is probably a bad
 idea.  *How can this be turned into a plugin?*

 Thanks much,

 Glen




-- 
Benjamin Sterling
http://www.KenzoMedia.com
http://www.KenzoHosting.com
http://www.benjaminsterling.com


[jQuery] Re: Synchronous JSONP

2008-01-08 Thread Glen Lipka
I think my thought process on this was messed up anyway.
Here is the use situation.  We are using JSONP to send activity on pages to
avoid cross-site scripting problems.  One of those activities is clicking on
a link.

The problem is that the JSONP is asynchronous so that when the link is
clicked, the page unloads before the JSONP has a chance to do it's thing.

What is the best way of allowing the JSONP to do it's thing and pause the
unload of the page long enough for it to work?

Glen


On Jan 8, 2008 1:37 PM, Benjamin Sterling [EMAIL PROTECTED]
wrote:

 Glen,
 I have never done it, but I say a while back that you can use the
 jQuery.extend method to overwrite a default method.  I will see if I can
 dig that up, but that may point you in the right direction in the mean time.



 On 1/8/08, Glen Lipka [EMAIL PROTECTED] wrote:
 
  Right now in 1.2.1 the JSONP method uses an asynchronous call to do it's
  thing.
  This sometimes causes a problem when we are sending a call about a
  click event on a link.  The page unloads before the JSONP is finished.
 
  Changing it to be optional (async or synchronous) helps fix that
  problem.
 
  Code we used inside jQuery (with a param call to .ajax)
 
  /* If the request is not async, we need to wait for the script to l oad
  before returning. */
  else if (!s.async) {
var done = false;
// Attach handlers for all browsers
  script.onload = script.onreadystatechange = function(){
if ( !done  (!this.readyState ||
  this.readyState == loaded || this.readyState == complete) )
  {
}
  };
}
 
  QUESTION:  Putting this directly into our copy of jQuery is probably a
  bad idea.  *How can this be turned into a plugin?*
 
  Thanks much,
 
  Glen
 



 --
 Benjamin Sterling
 http://www.KenzoMedia.com
 http://www.KenzoHosting.com
 http://www.benjaminsterling.com