[LRUG] Intermittent jQuery Problem

Abhishek Parolkar abhishek.parolkar at gmail.com
Tue Oct 27 08:25:09 PDT 2009


Hello Andrew,
 I suspect you might have a scoping problem, Sometimes you might see a weird
behavior of eventhandler calls when you try to access the data referenced
out of its scope.

On Tue, Oct 27, 2009 at 7:19 PM, Andrew Stewart
<boss at airbladesoftware.com>wrote:

>
>
>  $('#samples .results a.add').livequery('click', function(event) {
>    event.preventDefault();
>    // AJAX to add the sample to the story.
>    $.ajax({
>      type:       "POST",
>      url:        '/stories/2716/loans',
>      data:       {'loan[sample_id]':sample_id},          // <- this
> sometimes doesn't get sent
>

Where is sample_id ?, in which scope?

You might want to try something with scoping <http://pastie.org/671711>,
like this...

 $('#samples .results a.add').livequery('click', function(event) {

   event.preventDefault();

   var your_sample_id_goodness = sample_id_that_comes_from_well_bound_scope;

   return function(){
      // AJAX to add the sample to the story.
      $.ajax({
        type:       "POST",
        url:        '/stories/2716/loans',
        data:       {'loan[sample_id]': your_sample_id_goodness,
        beforeSend: function()     { sample.remove(); },
        success:    function(data) { $('#basket table tr:last').after(data);
}
      });
     }(); //End of return

  });

Regards,
Abhishek Parolkar
http://www.ohloh.net/accounts/parolkar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20091027/94e4c402/attachment-0003.html>


More information about the Chat mailing list