What I bring to you this time is how to usejquery's ajax to submit form data asynchronously. You can use jquery's ajax method to submit the form asynchronously. After success, the background returns json data,Callback functionProcessing, you can achieve asynchronous purposes without refreshing the page. This article will give you a good analysis.
The data processed in the form can be serialized using the serialize() method. If the submitted data includes a file stream, you need to use the FormDataobject:
Without Use the form data of the file: var data = $(form).serialize();
html:form form
jquery asynchronous processing
$("#submitAdd").click(function(){ var targetUrl = $("#addForm").attr("action"); var data = $("#addForm").serialize(); $.ajax({ type:'post', url:targetUrl, cache: false, data:data, dataType:'json', success:function(data){ alert('success'); }, error:function(){ alert("请求失败") } }) })
I believe you have mastered the method after reading the above introduction. For more exciting information, please pay attention to php Chinese websiteOtherrelated articles !
Related reading:
Use jQuery to deduplicate and sort arrays
How can it be done with JS Click to jump to the logged-in personal email
There are several ways to implement chain operations in PHP
The above is the detailed content of How to submit form data asynchronously using jquery's ajax. For more information, please follow other related articles on the PHP Chinese website!