I need to submit a form using JavaScript. The problem is my JavaScript POST request gets an “OK — 200” response. In order to make it 302 I think I need to use response.sendredirect in my JavaScript JSP function. Can any body tell me how to use it? With example code.
I need to submit a form using JavaScript. The problem is my JavaScript POST
Share
You won’t use
response.sendredirectin your JavaScript, there’s no such thing. If you’re submitting a form using JavaScript, then JavaScript is your HTTP client. It sends the POST request, with the form data, to whichever server you’re submitting to.The server then sends the HTTP response back to your JavaScript. It’s currently sending 200, but you’re looking for it to return a 302 redirect instead. You’d use
response.sendredirecton the server to do that — it’s not part of your JavaScript. There’s also no way to specify what sort of response you want in HTTP. It’s entirely up to the server.So, judging by your tags, you’ll want to use
response.sendredirectin your JSP code on the server. I’m afraid I’m not familiar with JSP, so I can’t really help there. It might help other answerers if you post some of your server-side code though — at the moment we’ve got no idea what’s going on there.