Home  >  Article  >  Web Front-end  >  jQuery synchronous submission sample code_jquery

jQuery synchronous submission sample code_jquery

WBOY
WBOYOriginal
2016-05-16 15:26:111063browse

The example in this article describes the jQuery synchronous submission method. Share it with everyone for your reference, the details are as follows:

Use the jQuery framework to submit demos synchronously

In some cases of strict detection or recursive or cyclic calls, incorrect results may occur if data cannot be returned synchronously, so synchronous submission technology needs to be used. jQuery defaults to an asynchronous operation, and the asynchronous attribute async needs to be explicitly set to false. , synchronization can be achieved.

Customized data submission

function GroupCheck(url, operate, check, group, joker) 
{ 
 var result = -1; 
 $.ajax( 
 { 
  type : "POST", 
  async : false, 
  url : url, 
  data : 
  { 
   operate : operate, 
   id_atGroup : group, 
   id_atJoker : joker 
  } 
 }).done(function(msg) 
 { 
  if (msg != null && msg != "") 
  { 
   if (msg == 0) 
   { 
    alert("操作成功2"); 
   } 
   else 
   { 
    alert("操作失败2"); 
   } 
  } 
  else 
  { 
   alert("服务器异常2"); 
   // check.checked = true; 
  } 
 }).fail(function() 
 { 
  // alert("error"); 
 }).always(function() 
 { 
  // alert("complete"); 
 }); 
 return result; 
}

Get form as submitted data

var $form = $('#theForm1'); 
url = $form.attr('action'); 
$.ajax( 
{ 
 type : "POST", 
 async : false, 
 url : url, 
 data : $form.serialize() 
}).done(function(msg) 
{ 
 // 完成代码 
});

Note that after 1.8, jqXHR.success(), jqXHR.error(), and jqXHR.complete() are abandoned and replaced by jqXHR.done(), jqXHR.fail(), and jqXHR.always ()

I hope this article will be helpful to everyone in jQuery programming.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn