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

jQuery dynamically implements ajax file download

php中世界最好的语言
Release: 2018-04-23 14:23:34
Original
2635 people have browsed it

This time I bring you jQueryDynamic implementation of ajaxFile download, what are the precautions for jQuery to dynamically implement ajax file download, the following is a practical case , let’s take a look.

// Ajax 文件下载 
jQuery.download = function(url, data, method){ 
// 获取url和data 
if( url && data ){ 
// data 是 
string
 或者 array/object 
data = typeof data == 'string' ? data : jQuery.param(data); 
// 把参
数组
装成 form的 input 
var inputs = ''; 
jQuery.each(data.split('&'), function(){ 
var pair = this.split('='); 
inputs+=&#39;<input type="hidden" name="&#39;+ pair[0] +&#39;" value="&#39;+ pair[1] +&#39;" />&#39;; 
}); 
// request发送请求 
jQuery(&#39;<form action="&#39;+ url +&#39;" method="&#39;+ (method||&#39;post&#39;) +&#39;">&#39;+inputs+&#39;</form>&#39;) 
.appendTo(&#39;body&#39;).submit().remove(); 
}; 
};
Copy after login

***That is, dynamically rendering the form, and then delete after submitting the form. ***

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

Jquery LigerUI detailed explanation of file upload steps

jquery dynamically loaded js file detailed explanation

Detailed explanation of the steps to asynchronously upload files using the PHP jQuery plug-in

The above is the detailed content of jQuery dynamically implements ajax file download. 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template