av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

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

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

問題描述

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

<!DOCTYPE html><html><head> <title>express 主頁</title> <meta charset='utf-8'> <script type='text/javascript' src='http://m.4tl426be.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://m.4tl426be.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://m.4tl426be.cn/wenda/jquery.min.js'></script></head><body><p>I love you!</p> <a href='http://m.4tl426be.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
相關文章:
主站蜘蛛池模板: 亚洲国产精品久久久久 | 91成人精品视频 | 国产午夜影院 | 亚洲一区日韩 | 日韩在线国产 | 精品福利一区二区三区 | 不卡一区二区三区四区 | 久久噜噜噜精品国产亚洲综合 | 国产成人精品免高潮在线观看 | 午夜电影在线播放 | 国产资源视频 | 国产精品欧美一区二区三区 | 99久久精品国产一区二区三区 | 成人国产精品久久久 | www日韩欧美 | 成人一区av | 手机在线一区二区三区 | 国产精品久久精品 | 日韩成人免费av | 精品一区二区三区91 | 国产一二三区电影 | 久久久毛片 | 成年人在线视频 | 99久久久久国产精品免费 | 国产精品久久久久久妇女 | 在线播放国产一区二区三区 | 亚洲国产精品日韩av不卡在线 | 国产网站在线播放 | 成人h电影在线观看 | 国产一区二区 | 国产精品入口麻豆www | 欧美日批 | 亚洲一区二区三区桃乃木香奈 | 女女百合av大片一区二区三区九县 | 蜜月aⅴ免费一区二区三区 99re在线视频 | 北条麻妃国产九九九精品小说 | 国内精品免费久久久久软件老师 | 国产精品色 | 古典武侠第一页久久777 | 搞黄网站在线观看 | 成人久久久久久久久 |