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

What are the methods for ajax asynchronous submission of forms?

php中世界最好的语言
Release: 2018-04-03 09:58:27
Original
2876 people have browsed it

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){ 
    } 
  });
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 ajaxSubmit()# provided by the jQuery Form plug-in ##Function

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!

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