Express + Multer,无需重定向 [英] Express + Multer without redirect

查看:80
本文介绍了Express + Multer,无需重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个代码,将文件上传到服务器.但是,在上传完成后,系统会将我重定向到上传路线.如何上传文件并停留在第一页?

I wrote a code that upload a file to server. But, just after the upload finish the system redirect me to the upload route. How can I upload a file and stay in the first page?

例如:

app.post('/upload',function(req,res){
  upload(req,res,function(err) {
    if(err) {
        return res.end("Error uploading file.");
    }
    res.end("File is uploaded");
  });    
});

上传完成后,我被重定向到localhost:3000/upload.我不要我想留在localhost:3000和当前会话中.

When the upload finish, I am redirected to localhost:3000/upload. I don't want it. I want to stay in localhost:3000 and in my current session.

提前谢谢.

推荐答案

如果要在浏览器不导航到提交表单的位置的情况下发出请求,则可能需要

If you want to make the request without the browser navigating to where the form is being submitted, then you may want to use XHR and FormData in one way or another to submit the form request instead.

这篇关于Express + Multer,无需重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆