Home > Web Front-end > JS Tutorial > body text

Asynchronous form submission under jquery Asynchronous cross-domain form submission_jquery

WBOY
Release: 2016-05-16 18:16:14
Original
1304 people have browsed it

1. Use the post submission method
2. Construct the form format
3. Call the ajax callback function in conjunction with the submit of the form form.
Use jQuery to submit the form code asynchronously:

Copy the code The code is as follows:

< html xmlns="http://www.w3.org/1999/xhtml">

Untitled page


<script> <br>jQuery(function($) { <br>// Use jQuery Asynchronous form submission<br>$('#f1').submit(function() { <br>$.ajax({ <br>url: 'ta.aspx', <br>data: $('#f1' ).serialize(), <br>type: "post", <br>cache : false, <br>success: function(data) <br>{alert(data);} <br>}); <br> return false; <br>}); <br>}); <br></script>










How to submit a form asynchronously across domains?
1. Use the cross-domain access feature of script and combine it with the data formatting of the form, so it can only be submitted using the get method. For security reasons, the browser is Post cross-domain submission is not supported.
2. Using JSONP to submit forms across domains is a better solution.
3. You can also use a dynamic program as an agent. Use a proxy to forward cross-domain requests.
Use jQuery to asynchronously submit form code across domains:
Copy code The code is as follows:



Untitled page


<script> <br>jQuery(function($) <br>{ <br>// Use jQuery to asynchronously submit the form across domains <br>$('#f1').submit(function() <br>{ <br>$.getJSON("ta.aspx?" $('#f1') .serialize() "&jsoncallback=?", <br>function(data) <br>{ <br>alert(data); <br>}); <br>return false; <br>}); <br> }); <br></script>









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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!