Since post()
doesn't have a return
statement, the onsubmit
function ends up returning undefined
.
Since it doesn't return false
, it doesn't cancel the normal behaviour of the form. Consequently, the form submits and unloads the page before the Ajax request resolves.
Putting in an alert
delays the page unload until you click OK, which gives time for the Ajax request to resolve.
return false
from the post
function to cancel the normal submission of the form instead.