I need to submit my form with an external button as follows and need to redirect the page after submit is success. The code below does not work and I am not using any AJAX for this.
// CODE 1: THIS DOES NOT WORK
$("#myButton").click(function(){
$("#myForm").submit(function(){
window.location.href = "test.jsp";
});
});
However, if I use some time delay as follow, it works:
// CODE 2: THIS WORKS
$("#myButton").click(function(){
$("#myForm").submit();
setTimeout(function(){
window.location.href = "test.jsp";
}, 2000);
});
Whenever there is a delay about 2 seconds between the submit() and redirection, everything works. But, I can not use the timer here and form submit call back is not working.
Can anyone tell me how can I solve it?