Home > Web Front-end > JS Tutorial > body text

Summary of several methods for asynchronously submitting forms using ajax

亚连
Release: 2018-05-23 11:09:33
Original
1711 people have browsed it

Below I will bring you a summary of several methods of asynchronously submitting forms using ajax. Let me share it with you now and give it as a reference for everyone.

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){ 
    } 
  });
Copy after login

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){ 
    } 
  }); 
}
Copy after login

Method 3

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

$('#myform').ajaxSubmit({
type: 'GET/POST',
url: 'xx.php',
dataType: 'json',
success: fn,
clearForm: true,
resetForm: true
}); 
//此函数会自动把选定的表单进行序列化并异步提交
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to solve the problem of arrays in AJAX requests

Ajax request and Filter cooperation case analysis

Summary of 5 ways Ajax solves cache

The above is the detailed content of Summary of several methods for asynchronously submitting forms using ajax. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template