jquery uses the dynamic rendering form feature to complete Ajax file downloads _jquery

Source: Internet
Author: User
Copy Code code as follows:

Ajax File Downloads
jquery.download = function (URL, data, method) {
Get URL and data
if (URL && data) {
Data is string or Array/object
data = typeof data = = ' String '? Data:jQuery.param (data);
Assemble the parameters into form input
var inputs = ';
Jquery.each (Data.split (' & '), function () {
var pair = this.split (' = ');
inputs+= ' <input type= "hidden" name= "' + pair[0] + '" value= "' + pair[1] + '"/> ";
});
Request Send requests
JQuery (' <form action= ' + URL + ' "method=" ' + (method| | ') Post ') + ' > ' +inputs+ ' </form> ')
. Appendto (' body '). Submit (). remove ();
};
};

That is, dynamically rendering the form, submitting the form, and then deleting it. ***

Invoke Instance
Copy Code code as follows:

$.download (' exceldownload.do ', ' find=commoncode ', ' post ');
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.