Two ways to implement ajax form submission with jquery

零下一度
Release: 2017-06-29 10:08:59
Original
1533 people have browsed it

Method 1:

Obtain the required data elements separately. The outer layer of the DOM structure does not need to include the form tag (suitable for small amounts of data and data elements scattered throughout the page)

$.ajax({   type: 'POST', url:'', data: { residence:[$('#region_1').val(),$('#region_2').val(),$('#region_3').val()], address:$('#address').val() }, dataType: 'json', success: function(data){ }, error:function(err){ } });
Copy after login

Method 2:

Need to wrap the form tag (suitable for large amounts of data and concentrated elements)

function AddHandlingFeeToRefund() {var AjaxURL= "../OrderManagement/AjaxModifyOrderService.aspx"; alert($('#formAddHandlingFee').serialize()); $.ajax({ type: "POST", dataType: "html", url: AjaxURL + '?Action=' + 'SubmitHandlingFee' + '&OrderNumber=' + $.trim($("#<%=this.txtOrderNumber.ClientID %>").val()), data: $('#formAddHandlingFee').serialize(), success: function (result) {var strresult=result; alert(strresult);//加载最大可退金额$("#spanMaxAmount").html(strresult); }, error: function(data) { alert("error:"+data.responseText); } }); }
Copy after login

html code:

Copy after login

The above is the detailed content of Two ways to implement ajax form submission with jquery. 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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!