0

When my event driven functions are called many repeat themselves.
Looking at debug I can see the functions being run more than once.
For instance the code below will produce:
First time: one original and one duplicate record added.
Second time: one original and two duplicate records added.
Third time: one original and three duplicate records added.
Fourth time: one original and four duplicate records added.

Now if I update a record it will go through the update six times.
And on and on.

$(function() {  
     $("#btn_add_this_card").click(function (e) {
         e.preventDefault();  
         $('#btn_add_this_card').fadeOut(300);   
         $.post("cards_insert.php", $("#input_form").serialize());
         reset();
         return;
        });
  });

 function reset()     
   {
     $("#div_form,  #div_cards, #cards_selected_category").hide();  
     $(".btn").hide();
     $( "#btn_add_card").show()
     $("#div_categories" ).load( "cards_get_categories.php" ); 
     return;  
   } ; 
3
Contributors
4
Replies
40
Views
2 Years
Discussion Span
Last Post by Lonestar Jack
0

In your code above is line 2 being run multiple times? Are you wiring the even handler up again and again somehow? Difficult to say without seein the whole thing in context but that's what it sounds like to me.

0

Line 2 does not appear again.
There are 2 more handlers -- update and delete -- which fall prey to the same problem.
Here are the debug errors after I cleared the debug error stream and pressed the delete button once after I had just deleted 4-5 records. Each time it would add an extra trip through the cards_delete.php routine.
It just gets cumulative. There are no counters controling the javascript invokes either

POST http://127.0.0.1/cards/cards_delete.php

200 OK
        61ms    
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        108ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        110ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        135ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        109ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        159ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        197ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        194ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        188ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php
200 OK
        210ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php
200 OK
        241ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        248ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        245ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        287ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        293ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        298ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        302ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        331ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        339ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        378ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        368ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        368ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        392ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        399ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        396ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        421ms   
jquery-... > eval (line 4)
POST http://127.0.0.1/cards/cards_delete.php

200 OK
        409ms   
jquery-... > eval (line 4)
GET http://127.0.0.1/cards/cards_get_categories.php

200 OK
        430ms
0

Using console.trace I was able to detect a couple of javascript files stepping on each other.
Basically I was in doubt of what javascript was necessary in an AJAX called file vs in the calling file.
It is all fixed now and console.trace box will be in my tool.
Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.