[LRUG] Intermittent jQuery Problem

Andrew Stewart boss at airbladesoftware.com
Tue Oct 27 06:49:31 PDT 2009


Hi El Rug,

I have a jQuery AJAX call which sometimes doesn't POST its data.  The  
javascript looks like this:

   $('#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
       beforeSend: function()     { sample.remove(); },
       success:    function(data) { $('#basket table  
tr:last').after(data); }
     });
   });

The HTML it's attached to looks like this (in HAML):

   #samples
     .results
       %table
         %tr
           %th.icon  
           %th Description
         - for sample in samples
           %tr[sample]
             %td.icon= link_to image_tag('/images/icons/add.png'),  
'', :class => 'add'
             %td= sample.description

A good post looks like this in the log:
  Parameters: {"action"=>"create", "story_id"=>"2716",  
"controller"=>"loans", "loan"=>{"sample_id"=>"4787"}}

A bad post looks like this in the log:
   Parameters: {"action"=>"create", "story_id"=>"2716",  
"controller"=>"loans"}

I can't figure out why sometimes the data part of the POST doesn't get  
sent.  I also can't reproduce this in development, which doesn't  
help.  It's happening intermittently but frequently in production.

Any ideas?

Thanks,
Andy Stewart

-------
http://airbladesoftware.com




More information about the Chat mailing list