1,105,625 Community Members

ajax should call only once

Member Avatar
Eagle.Avik
Junior Poster in Training
80 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

hi, i want ajax to be called only once, but insted it calls everytime when i click on the button.
my script:

$(document).ready(function(){
  $("#modal-launcher-user").click(function(){
$('#preloader_image_edit').show();      

$.ajax({

  url: "image_edit.php",
  cache: false,

})
  .done(function( html ) {
    $("#preloader_image_edit").hide();
    $( "#results_image_edit" ).append( html );
  });
  });
  });
Member Avatar
pritaeas
mod_pritaeas
11,332 posts since Jul 2006
Reputation Points: 1,420 [?]
Q&As Helped to Solve: 1,835 [?]
Skill Endorsements: 156 [?]
Moderator
Featured
Sponsor
 
0
 
$('#modal-launcher-user').unbind('click');

Will remove the click handler.

Member Avatar
Airshow
WiFi Lounge Lizard
2,798 posts since Apr 2009
Reputation Points: 333 [?]
Q&As Helped to Solve: 393 [?]
Skill Endorsements: 11 [?]
Team Colleague
 
2
 

That is what jquery's .one() is for.

$("#modal-launcher-user").one('click', function() {
    ...
});
Question Answered as of 3 Months Ago by pritaeas and Airshow
Member Avatar
Eagle.Avik
Junior Poster in Training
80 posts since Aug 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

thnx :)

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: