How to submit form data asynchronously using jquery's ajax

php中世界最好的语言
Release: 2017-12-31 11:11:21
Original
1408 people have browsed it

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

Copy after login

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("请求失败") } }) })
Copy after login


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!

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!