Use jquery to implement Ajax asynchronous form submission for partial refresh

Source: Internet
Author: User

Jquery learning notes

After the form is submitted, the page is not refreshed, but partial refresh. Only the ID of the form to be submitted is required.

If you use GET requests, pay attention to Chinese garbled characters, jquery will first use iso8859-1 decoding, and then sent to the server, if you use post requests, the Chinese content is directly submitted to the server for resolution.

Use the jquery-1.4.2.js and jquery. Form. js plug-ins.

If you create a new JS file, add

Document. write ("<SCRIPT type = 'text/JavaScript 'src = 'jquery-1.4.2.js'> </SCRIPT>") <br/> document. write ("<SCRIPT type = 'text/JavaScript 'src = 'jquery. form. js'> </SCRIPT> ")

// Dynamic loading page <br/> // ID Display Page's container component Id2 <br/> // URL to load the page url <br/> // gop get request or post request, default get <br/> function loadpage (ID, URL, GOP) {<br/> $ ("#" + id ). addclass ("loader"); <br/> $ ("#" + id ). append ("loading ...... "); <br/> var type = (GOP =" Post "? "Post": "Get"); <br/> $. ajax ({<br/> type: type, <br/> URL: URL, <br/> cache: false, <br/> error: function () {<br/> alert ('Load page' + URL + 'error! ') <Br/>}, <br/> success: function (content) {<br/> $ ("#" + id ). empty (). append (content); <br/> $ ("#" + id ). removeclass ("loader"); <br/>}< br/> }); <br/>}</P> <p> // partial submission form <br/> function formsubmit (formid, divid, URL) {<br/> $ ('#' + formid ). submit (function () {<br/> $ (this ). ajaxsubmit ({<br/> Target: '#' + divid, <br/> URL: URL, <br/> error: function () {<br/> alert ('Load page' + URL + 'error! ') <Br/>}< br/>}); <br/> return false; <br/>}); <br/>}< br/>

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.