I have been trying to solve this problem whole day,but it seems I am not able.
Here is my code:
function mailcheckajax(email){
//var add = $('#mail').val();
//window.location = "index.php?address="+add;
//alert(window.location.pathname);
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
var xmlhttp;
// code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
if(xmlhttp.responseText != "valid"){
window.mailerror = "true";
} else {
window.mailerror="false";
}
}
}
xmlhttp.open("GET","/application/views/client/mailvalidate.php?address="+$('#'+email).val(),true);
xmlhttp.send();
return "true";
}
It calls this function and comes another line of code:
mailcheckajax('studentEmail');
if (checkvalidate == "true") {
if (validateStep(oldstep) == false) {
$("html, body").animate({
scrollTop: 0
}, "slow");
return false;
}
}
I need that on onclick() firstly was executed mailcheckajax function fully in order to get response from server using ajax and only after that other code.Or do not exit from function before it gets ajax response.
Can anyone help?