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
});
//此函数会自动把选定的表单进行序列化并异步提交
Recommended reading:
How to deal with the ajax cross-domain access error 501How to implement the AJAX request arrayThe 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!