Saturday 21 December 2019

Unable to redirect after using XMLHttpRequest.send()

Hello, I've recently been hitting my head on a wall over what feels like a simple problem.In the past, I was using simple post forms, but since then, a few things changed, and instead of using a form, I ended up using multiple input fields, with a submission button that uses XMLHttpRequest.send()When it was a simple form, the backend itself was able to redirect with a simple res.redirect, but since changing over to this new posting method, I've not been able to do so.Not only that, but if I bypass this problem by redirecting in the client-side js, it stops the back-end from finishing its task (Login/Registration.)The chunk of code I've been using to send the details is this:xhr.open("POST", '/user/login', true); xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); xhr.send(JSON.stringify(userDetails));

Submitted December 21, 2019 at 04:39PM by monkey_programmer

No comments:

Post a Comment