Im trying to solve form submitting with ajax, the php runs, but the form is stucked. This function does not run: ajax.onreadystatechange = function()
btw the status is 0 for all the time as the console said... so i did't get whats the problem here.
My code:
<script>
function _(id){ return document.getElementById(id); }
function submitForm(){
_("btnSubmit").disabled = true;
var formdata = new FormData();
formdata.append( "name", _("name").value );
formdata.append( "email", _("email").value );
formdata.append( "phone", _("phone").value );
formdata.append( "officeAddress", _("officeAddress").value );
formdata.append( "officeType", _("officeType").value );
formdata.append( "message", _("message").value );
var ajax = new XMLHttpRequest();
ajax.open( "POST", "contact.php");
console.log(ajax.status)
ajax.onreadystatechange = function() {
if(ajax.readyState == 4 && ajax.status == 200) {
if(ajax.responseText == "success"){
_("btnSubmit").disabled = false;
$('#myAlert').show('fade');
} else {
_("btnSubmit").disabled = false;
}
}
}
console.log(ajax.status)
ajax.send ( formdata );
}
</script>