Express + Multer without redirect

好久不见. 提交于 2020-01-07 03:07:19

问题


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?

For example:

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

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.

Thanks in advance.


回答1:


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.



来源:https://stackoverflow.com/questions/40846303/express-multer-without-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!