Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting jquery ajaxStop to only fire once everytime

Tags:

jquery

ajax

For some reason my ajaxStop code is firing twice right now and I need to limit it to just one time.

$('.submit').bind('click', function(e) {

$("#fileupload").ajaxForm({
        target: '#status'
}).submit();


$(document).ajaxStop(function() {
         var mysrc = $("#status").find('img').attr("src");
         $(".empty:first").removeClass("empty").removeClass("ui-state-default").addClass("ui-state").append('<img src="'+mysrc+'" width="45" height="60" class="expand"/>');
     });     

});
like image 926
Blynn Avatar asked May 05 '13 04:05

Blynn


1 Answers

try using .one(), like:

$(document).one("ajaxStop", function() {
   var mysrc = $("#status").find('img').attr("src");
   $(".empty:first").removeClass("empty").removeClass("ui-state-default").addClass("ui-state").append('<img src="'+mysrc+'" width="45" height="60" class="expand"/>');
});   
like image 106
Sudhir Bastakoti Avatar answered Sep 27 '22 20:09

Sudhir Bastakoti