Post form data and redirect not working
Hello,
I have a form from named otpForm from where I post data to actionCheck.csp and redirect it to another csp file cmain.csp after form post and the redirect is not working. I tried to debug and check the value in the cmain.csp but noticed that redirec t is not working.
Do you know if window.location.href = "cmain.csp"; is working with CSP?
Can someone guide me what to do here please
Thank you
Here is what I did:
//post and redirect form data
<script type="text/javascript">
jQuery(document).ready(function () {
var first = $("#first");
var sec = $("#sec");
var third = $("#third");
var fourth = $("#fourth");
var fifth = $("#fifth");
var errorField = $("#error");
var btn = $("#sendotp");
btn.click(function (e) {
e.preventDefault();
var aaa = first.val() + sec.val() + third.val()+fourth.val() + fifth.val();
if (
first.val() !== "" &&
sec.val() !== "" &&
third.val() !== "" &&
fourth.val() !== "" &&
fifth.val() !== ""
) {
$.post('actionCheck.csp', { DATA: aaa })
.done(function (response) {
//console.log(response);
alert("response: "+response)
if (response == "1"){
window.location.href = "cmain.csp";
} else {
$( ".form-control" ).addClass( "error" );
var msg = (response == 0) ? "wrong aaa code" : "wrong aaa code"
showToast("Error: " + msg, "#ad0f17");
}
})
.fail(function (xhr, status, error) {
$( ".form-control" ).addClass( "error" );
showToast("Error: " + error, "#ad0f17");
});
} else {
$( ".form-control" ).addClass( "error" );
showToast("Please enter the verification code", "#ad0f17");
//errorField.html("")
}
});
});
</script>
Try to use "window.location.replace" instead of "window.location.href"
if (response == "1") { window.location.replace("cmain.csp"); }