亚洲免费在线视频-亚洲啊v-久久免费精品视频-国产精品va-看片地址-成人在线视频网

您的位置:首頁技術(shù)文章
文章詳情頁

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

瀏覽:164日期: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方法的第一個(gè)參數(shù)

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');});

你可以瀏覽器單獨(dú)訪問http://localhost:3000/download看看能不能下載下來,你現(xiàn)在直接404后臺(tái)服務(wù)都沒ready,先別前后端的聯(lián)調(diào)吧。

標(biāo)簽: Html5
相關(guān)文章:
主站蜘蛛池模板: 成人国产视频在线观看 | 国产精品久久久久毛片真精品 | 国产日韩久久 | 欧美色欧美亚洲高清在线视频 | 美女久草| 国产精品亚洲精品爽爽 | 欧美黄色一级在线 | 2022男人天堂 | 欧美日韩综合网在线观看 | 亚洲成人黄色网 | 国产成人aa在线视频 | 欧美一级淫片免费观看 | 在线视频中文字幕 | 香蕉久久久久 | 在线播放国产一区二区三区 | 黄色片成年人 | 亚洲大片免费观看 | 日本www免费| 国产aaaaa一级毛片 | 91成人免费观看 | 国产成人深夜福利在线观看 | 香蕉99国内自产自拍视频 | 国产精品毛片在线大全 | 成人a一级毛片免费看 | 4455永久在线毛片观看 | 国产短视频精品一区二区三区 | 亚洲精品午夜久久久伊人 | 久久精品国内偷自一区 | 97欧美精品一区二区三区 | 中文字幕在线无限2021 | 亚洲精品久久久久综合中文字幕 | 国产精品亚洲一区二区三区 | 亚洲天堂一区在线 | 曰本美女高清在线观看免费 | 久久亚洲欧洲日产国码 | 欧美在线一区二区三区 | 99久久一区二区精品 | 国产成人午夜精品免费视频 | 久久午夜精品视频 | 亚洲精品日韩在线一区 | 一道本久久|