色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

html5 - node.js下載失敗,求大神解釋

瀏覽:137日期:2023-10-08 13:51:42

問題描述

使用express框架下載文件,但是失敗了,直接看代碼

<!DOCTYPE html><html><head> <title>express 主頁</title> <meta charset='utf-8'> <script type='text/javascript' src='http://www.lshqa.cn/wenda/jquery.min.js'></script></head><body><p>I love you!</p><button>click there to download a pictutre</button><script type='text/javascript'>$(function(){ $(’button’).click(function(){ $.ajax({url:’/download’,type:’get’,success:function(result){ alert('Resquest has been received!');} }) })})</script></body></html>以下是node.js代碼 var express = require('express');var app = express();app.use(express.static(’public’));app.locals.title = 'My app';app.get('/',function(req,res){console.log('resquest has been received!');res.sendFile('public/index.html');res.end();})app.get('/download',function(req,res){res.download(’public/example.jpg’,’example.jpg’,function(err){if(err) console.log(err);else console.log('download successfully'); });})app.listen(3000);console.log('OK');

html5 - node.js下載失敗,求大神解釋

求解疑

問題解答

回答1:

你的下載按鈕我建議直接寫成

<a href='http://www.lshqa.cn/download' download>下載</a>

http://www.expressjs.com.cn/4...注意res.download方法的第一個參數

res.download(’/report-12345.pdf’, ’report.pdf’, function(err){ if (err) { // Handle error, but keep in mind the response may be partially-sent // so check res.headersSent } else { // decrement a download credit, etc. }});

然后你的圖片雖然尺寸很大,但是太模糊了。。。

回答2:

index.html

<!DOCTYPE html><html><head> <title>express 主頁</title> <meta charset='utf-8'> <script type='text/javascript' src='http://www.lshqa.cn/wenda/jquery.min.js'></script></head><body><p>I love you!</p> <a href='http://www.lshqa.cn/download' download>下載</a></body></html>

node.js

var express = require('express');var app = express();app.use(express.static(’public’));app.locals.title = 'My app';app.get('/',function(req,res){console.log('resquest has been received!');res.sendFile('public/index.html');res.end();})app.get('/download',function(req,res){ res.download(’public/example.jpg’, ’example.jpg’,function(err){if(err) console.log(err);else console.log('download successfully'); });})app.listen(3000, function(err) { if(err) console.error(err); console.log('OK');});

你可以瀏覽器單獨訪問http://localhost:3000/download看看能不能下載下來,你現在直接404后臺服務都沒ready,先別前后端的聯調吧。

標簽: Html5
相關文章:
主站蜘蛛池模板: 免费视频日本 | 欧美成人精品三级网站 | 久久在线影院 | 亚洲一区二区精品视频 | 视频在线二区 | 欧美成人26uuu欧美毛片 | 日本免费在线观看视频 | 亚洲欧美日韩三级 | 国产精品一区二区久久精品涩爱 | 99久久伊人一区二区yy5099 | 久草网站在线观看 | 亚洲成人高清在线 | 久久aa毛片免费播放嗯啊 | 精品亚洲欧美高清不卡高清 | 国产波多野结衣中文在线播放 | 日韩在线视频一区二区三区 | 第一区免费在线观看 | 国产美女做爰免费视 | 亚洲一区二区三区高清网 | 日韩久久综合 | 黄色福利小视频 | 操美国女人 | 亚洲欧美在线视频免费 | 波多野结衣免费免费视频一区 | 99久久国产免费福利 | 最新国产午夜精品视频不卡 | 免费观看大片毛片 | 欧美国产日本精品一区二区三区 | 99久久精品免费看国产免费软件 | 国内精品久久久久久中文字幕 | 亚洲一区二区在线免费观看 | 精品久久久久久综合日本 | 精品国产欧美一区二区五十路 | 国产在线一区二区三区 | 草久在线观看 | 亚洲视频免 | 成人毛片免费免费 | 最近韩国日本免费免费版 | 日韩在线无 | 日本九六视频 | 九九视频在线 |