+1 vote
by
Chrome works as I need, first sends the form and then leaves onClick, but from the phone form is not sent, immediately redirect. How do I fix it?
<table border="0" width="100%" id="table1" cellspacing="1" cellpadding="2">
<br>
<tr><b>ВАШ ТЕКСТ</b><font color="red">*</font>:<br>
<textarea rows="7" name="f3" cols="30" style="width:50%;"></textarea></tr>
<tr><td colspan="2" align="center"><input type="submit"
value="Отправить СООБЩЕНИЕ" onClick='location.href="ССЫЛКА НА СТОРОННИЙ РЕСУРС"'></td></tr>
</table>
by
alexalexes , there is a redirect, from the PC form is sent from the phone does not have time
by
Did the message catch on?
by
It would be more correct to do it through the response handler:
Try to use:
request.onload = function()
{
window.location.href="https://google.com"; // перенаправляем на гугль.
};
I posted the answer. Mark it as a solution. PS: note that send is called at the very end. PSS: Don't abuse the likes in the comments.
by
Then do a redirect delayed:
setTimeout(function()
{
window.location.href="https://google.com"; // перенаправляем на гугль.
}, 3000);
by
alexalexes , Finally WOOOOOOOOAAAAAAAAAAAAAAAAAAAAA. Thank you so much.

1 Answer

0 votes
by
 
Best answer
<script type="text/javascript">
$( "form" ).submit(function( event ) {
event.preventDefault();
var formData = new FormData();
formData.append("f1", document.querySelector("input[name='f1']").value);
formData.append("f2", document.querySelector("input[name='f2']").value);
formData.append("f3", document.querySelector("textarea[name='f3']").value);
var request = new XMLHttpRequest();
request.open('POST', 'http://mydape.ru');
request.onload = function()
{
window.location.href="https://google.com"; // перенаправляем на гугль.
};
request.send(formData);
});
</script>
...