Home > Web Front-end > JS Tutorial > JQuery+AJAX implements file download

JQuery+AJAX implements file download

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

This time I bring you JQuery AJAX implementation File download, what are the precautions for JQuery AJAX implementation file download, the following is a practical case, one Get up and take a look.

JQuery's ajaxfunction has only return types such as xml, text, json, html, etc. There is no "stream" type, so we need to implement ajax download and cannot use the corresponding ajax function. Download the file. But you can use js to generate a form, use this form to submit parameters, and return "stream" type data. During the implementation process, the page was not refreshed

var form=$("<form>");//定义一个form表单
form.attr("style","
display
:none");
form.attr("target","");
form.attr("method","post");
form.attr("action","exportData");
var input1=$("<input>");
input1.attr("type","hidden");
input1.attr("name","exportData");
input1.attr("value",(new Date()).getMilliseconds());
$("body").append(form);//将表单放置在web中
form.append(input1);
form.submit();//表单提交
Copy after login

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:

Detailed explanation of the steps for asynchronous uploading of files by the PHP jQuery plug-in

How jQuery converts the url address to obtain the url directory

Detailed explanation of the steps for jquery to parse XML string XML files (with code)

The above is the detailed content of JQuery+AJAX implements 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