[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) {
     // AJAX to add the sample to the story.
       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):

           %th Description
         - for sample in samples
             %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",  

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?

Andy Stewart


More information about the Chat mailing list