napsternapster Posted August 18, 2009 Share Posted August 18, 2009 Morning people, I'm using ajax to validate inforamtion entered by the user. The following is the code used to do the validation. function validateServer(f) { server_error = 0; correct = 0; //get information from the form a tag id's var info_select = document.getElementById("info_type_select").value; var info_input = document.getElementById("info_type_input").value; var d_select = document.getElementById("detailed_type_select").value; var d_input = document.getElementById("detailed_type_input").value; var i_select = document.getElementById("detailed_identifiers_select").value; var i_input = document.getElementById("detailed_identifiers_input").value; var g_select = document.getElementById("group_type_select").value; var g_input = document.getElementById("group_type_input").value; //1 = information type , 2 = group type , 3 = detailed information type , 4 = identifier information type var urlinfo_input = "checking_information.php"; urlinfo_input = urlinfo_input+"?information="+info_input+"&id_select="+info_select+"&type=1"; executeAjax(urlinfo_input,"GET","info_type_select","info_type_input","type_error"); var urlgroup_input = "checking_information.php"; urlgroup_input = urlgroup_input+"?information="+g_input+"&id_select="+g_select+"&type=2"; executeAjax(urlgroup_input,"GET","group_type_select","group_type_input","group_error"); var urldetailed_input = "checking_information.php"; urldetailed_input = urldetailed_input+"?information="+d_input+"&id_select="+d_select+"&type=3"; executeAjax(urldetailed_input,"GET","detailed_type_select","detailed_type_input","detailed_error"); var urlidentifier_input = "checking_information.php"; urlidentifier_input = urlidentifier_input+"?information="+i_input+"&id_select="+i_select+"&type=4"; executeAjax(urlidentifier_input,"GET","detailed_identifiers_select","detailed_identifiers_input","identifier_error"); if(server_error == 0 ) { //f.submit(); alert("submit"); } } function executeAjax(url,method,select_id,input_id,error_id) { var xmlhttp = new GetXmlHttpObject(); if(method == 'GET') { xmlhttp.open(method, url, true); xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { if(xmlhttp.responseText != 0) { server_error++; document.getElementById(error_id).innerHTML = xmlhttp.responseText; document.getElementById(select_id).style.background = 'red'; document.getElementById(input_id).style.background = 'red'; } } } xmlhttp.send(null); } Problem xmlhttp.open(method, url,true); When I use true to open the php script it processes javascript before getting the response from php page in all 4 browsers chrome,IE7,Opera and firefox xmlhttp.open(method, url,false); when I use false it works well to other browsers except firefox.on firefox it does not get any response the xmlhttp.responseText and it submits without getting any response from php script. I thank you in advice for your assistance Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.