Reputation: 11
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.
Upvotes: 1
Views: 680
Reputation: 106736
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.
Upvotes: 1