Submit an Ajax request before submitting the form

Is it possible to send ajax request in onsubmit () of a form? I tried this and the results were rough, mainly because probably if the browser needs more time to send my request than when sending the original form, my request will be rejected as soon as the location of the loaded page changes, so sometimes it’s never even does not get to the server.

Basically, I want to add an audit log collector that collects login events, I want to connect them to existing applications with minimal intrusion.

+5
source share
3 answers

. , AJAX.

onsubmit AJAX false ( ). AJAX , .

:

<form name="myform" onsubmit="javascript: startAjax(); return false;">
...
<script type="text/javascript">
function startAjax() {} // Calls ajaxComplete() when finished

function ajaxComplete()
{
  document.myform.submit();
}
</script>
+18

, ajax .

:

xmlhttp.open("GET", imageUrlClickStream, false);

, , , ajax .

0

onsubmit onclick, , onsubmit .

<form name="myform" onclick="javascript: startAjax(); return false;">
...
<script type="text/javascript">
function startAjax() {} // Calls ajaxComplete() when finished

function ajaxComplete()
{
  document.myform.submit();
}
</script>
0

All Articles