Use jQuery. ajax to upload forms based on XMLHttpRequest and FormData
Source: Internet
Author: User
XMLHttpRequest has been released for a long time, and W3C has introduced some good features. Ruan Yifeng has a good article on this, which summarizes the XMLHttpRequestLevel2 user guide. Eliminate outdated browsers in actual use, which is the simplest to use... syntaxHighlighter. all (); XMLHttpRequest has been released for a long time, and W3C has introduced some good features. Ruan Yifeng has a good article on this, which summarizes the Usage Guide of XMLHttpRequest Level 2. Excluding outdated browsers in actual use, the simplest way to use is to generate the submit event of the FORM hander FORM using the standard HTML syntax, generate XMLHttpRequest with FormData to submit data, return false to submit to process XMLHttpRequest results, and form submission in ajax mode is completed. Of course, this supports file upload. If we use jQuery. the ajax code is like this. Js code: $ ('yourform '). submit (function () {var formdata = new FormData (this); $. ajax ({type: 'post', url: '/yourpath', data: formdata,/*** must be false to automatically add the correct Content-Type */contentType: false,/*** must be false to avoid jQuery's default processing of formdata * XMLHttpRequest will correctly process formdata */processData: false }). then (function () {// doneCal}, function () {// failCal}); return false ;}); that's simple under standard. In many cases, users are required to use modern browsers. For example, for editing, it corresponds to a customized enterprise user.
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