Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 1.26 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $(function() {
  2.     $("#submitButton").click(function() {
  3.         // Disable the submit button
  4.         $(this).attr("disabled", "disabled");
  5.  
  6.         // Show the loading image
  7.         $(".loading").show();
  8.  
  9.         // Serialize the form values for AJAX submission
  10.         var $formParamsString = $(this).closest("form").serialize();
  11.  
  12.         $.ajax({
  13.             type: "POST",
  14.             url: "myService.cfm",
  15.             dataType: "JSON",
  16.             data: $formParamsString,
  17.             async: false,
  18.             success: function(data) {
  19.                 alert("Form values saved!")
  20.             },
  21.             error: function() {
  22.                 alert("Form values not saved!")
  23.             }
  24.         });
  25.  
  26.         // Hide the loading image
  27.         $(".loading").hide();
  28.  
  29.         // Re-enabled the submit button
  30.         $(this).removeAttr("disabled");
  31.  
  32.         // Prevent form post
  33.         return false;
  34.     });
  35. });
  36.        
  37. <input
  38.     id="submitButton"
  39.     name="submitButton"
  40.     type="submit"
  41.     value="Submit"
  42.     class="submitButton" />
  43. <span class="loading"></span>
  44.        
  45. .loading {
  46.     background: url("/images/loading.gif");
  47. }
  48.        
  49. // Hide the loading image
  50. $(".loading").hide();
  51.  
  52. // Re-enabled the submit button
  53. $(this).removeAttr("disabled");