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

Untitled

By: a guest on Jun 4th, 2012  |  syntax: None  |  size: 2.44 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Form submit based on ajax response in jQuery
  2. $('#submit_zipcode_frm').submit(function(event){
  3.                     event.preventDefault();
  4.                     var self = this;
  5.                     $(".loader img").show();
  6.                     z = $('#zipcode');
  7.                     if(z.val() != '' && z.val().length == 5) {
  8.                         var value = z.val().replace(/^ss*/, '').replace(/ss*$/, '');
  9.                         var intRegex = /^d+$/;
  10.                         if(!intRegex.test(value)) {
  11.                             $(".loader img").hide();
  12.                             error($(".zipcode_field"));
  13.                             return false;
  14.                         }
  15.                     } else {
  16.                         $(".loader img").hide();
  17.                         error($(".zipcode_field"));
  18.                         return false;
  19.                     }
  20.  
  21.                     $.ajax({
  22.                         url: "/ajax/save/zipcode",
  23.                         type: 'GET',
  24.                         async: false,
  25.                         cache: false,
  26.                         dataType: 'html',
  27.                         data:   {zipcode: $('.zipcode_field').val()},
  28.                         success: function(data) {
  29.                                 if(data == 'false'){
  30.                                     $(".loader img").hide();
  31.                                     error($(".zipcode_field"));
  32.                                     return false;
  33.                                 }else{
  34.                                     self.submit();
  35.                                     getList();
  36.                                 }
  37.                         }
  38.                     });
  39.             });
  40.        
  41. <form id="submit_zipcode_frm" class="submit_zipcode" method="post" action="/go" target="_blank">
  42.                         <div class="zipcode_container">
  43.                             <span class="loader">
  44.                                 <img src="/assets/img/loader.gif" style="display: none;"/>
  45.                             </span>
  46.                             <input type="text" class="zip_input zipcode_field ghost" id="zipcode" name="zipcode"  value="Enter your Zip"/>
  47.                             <div class="start_btn">
  48.                                 <button type="submit">Submit</button>
  49.                             </div>
  50.                             <div class="clear"></div>
  51.                         </div>
  52.                         <div class="clear"></div>
  53.                         </form>