Home  >  Article  >  Web Front-end  >  What are the methods for ajax asynchronous submission of forms?

What are the methods for ajax asynchronous submission of forms?

php中世界最好的语言
php中世界最好的语言Original
2018-04-03 09:58:272836browse

This time I will bring you some methods of ajax asynchronous submission of forms, and what are the precautions for ajax asynchronous submission of forms. The following is a practical case, let's take a look.

Here are three commonly used submission methods

Method 1

Manually collect all user input, encapsulate it into a large "k1=v1&k2=v2..." key-value pair form, and use $.post(url, data,fn) to submit the data to the server

$.ajax({ 
    type:'post',   
    url:'Notice_noTipsNotice', 
    data:'k1=v1&k2=v2...', 
    cache:false, 
    dataType:'json', 
    success:function(data){ 
    } 
  });

Method 2

单序列化:$('#myform').serialize( ); 其返回值就是“k1=v1&k2=v2...”键值对形式,再发起异步请求即可。
function noTips(){ 
  var formParam = $("#form1").serialize();//序列化表格内容为字符串 
  $.ajax({ 
    type:'post',   
    url:'Notice_noTipsNotice', 
    data:formParam, 
    cache:false, 
    dataType:'json', 
    success:function(data){ 
    } 
  }); 
}

Method 3

Use ajaxSubmit()# provided by the jQuery Form plug-in ##Function

$('#myform').ajaxSubmit({
type: 'GET/POST',
url: 'xx.php',
dataType: 'json',
success: fn,
clearForm: true,
resetForm: true
}); 
//此函数会自动把选定的表单进行序列化并异步提交
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to deal with the ajax cross-domain access error 501


How to implement the AJAX request array

The above is the detailed content of What are the methods for ajax asynchronous submission of forms?. For more information, please follow other related articles on the PHP Chinese website!

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