code_junkie

How do I disallow clicking on a link while an ajax request is in progress

Nov 13th, 2011
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. var contact= {
  2. send: function() {
  3. $.ajax({
  4. type: "POST",
  5. url: "ws/ContactService.asmx/SendEmail",
  6. data: '{"fromEmail":"' + $("#email").val() + '", "fromName":"' + $('#name').val() + '", "subject":"' + $('#subject').val() + '", "message":"' + $('#message').val() + '"}',
  7. contentType: "application/json; charset=utf-8",
  8. dataType: "json",
  9.  
  10. error: function() {
  11.  
  12. alert("Error");
  13.  
  14. },
  15. success: function(msg) {
  16. alert(msg.d);
  17. },
  18. complete: function() {
  19. $("#send").text("Send");
  20.  
  21. }
  22. });
  23. }
  24. };
  25. $(document).ready(function() {
  26. $("#send").("click", function() {
  27. $("#send").text("Sending...");
  28. contact.send();
  29. });
  30. }
  31. );
  32.  
  33. var contact = {
  34. inprogress: false,
  35. send: function() {
  36. if (contact.inprogress)
  37. return;
  38.  
  39. contact.inprogress = true;
  40. $.ajax({
  41. ...
  42. complete: function() {
  43. $("#send").text("Send");
  44. contact.inprogress = false;
  45. }
  46. });
  47. }
  48. };
Add Comment
Please, Sign In to add comment