FredFogg Posted June 27, 2010 Share Posted June 27, 2010 I have a webpage where the user enters an email address and hits the tab key to activate a function onChange and I use Ajax to read a MySQL database and then displays a message if that email address is already on the database or not. It works fine in IE8, but in Safari it doesn't work. Here is my function to check for which XML Http Object: function GetXmlHttpObject(){ if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } And here is how I call it: var xxmlHttp; xxmlHttp=GetXmlHttpObject(); if (xxmlHttp==null){ alert ("Browser does not support HTTP Request"); return; } I am not getting the alert, it just tabs to the next field. What am I doing wrong. I need this to work with all browsers. So then I put alerts in my function GetxmlHttpObject and it displays the alert saying that it got the xml requets for Safari. So why doesn't it display the message. I am sending the message to a div id tag that I have below the input textbox for the email address. <div id="output1" style="color: blue;"></div> and here is the code to check the email address for duplicate. function omrCheckEmail(){ var divid = 'output1'; var loadingmessage = 'Processing...'; var xxmlHttp; xxmlHttp=GetXmlHttpObject(); if (xxmlHttp==null){ alert ("Browser does not support HTTP Request"); return; } xxmlHttp.onreadystatechange = function(){ if (xxmlHttp.readyState > 0 && xxmlHttp.readyState < 4){ document.getElementById(divid).innerHTML=loadingme ssage; } if (xxmlHttp.readyState == 4) { emBoolean = xxmlHttp.responseText; if (emBoolean == 'true') { document.getElementById(divid).innerHTML="THIS EMAIL HAS REGISTERED!"; } else { document.getElementById(divid).innerHTML="THIS EMAIL HAS NOT REGESTERED!"; } } } var queryString = '&email=' + (document.getElementById('custom').value); xxmlHttp.open("POST", "omrCheckEmail.php", true); xxmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xxmlHttp.setRequestHeader("Content-length", queryString.length); xxmlHttp.setRequestHeader("Connection", "close"); xxmlHttp.send(queryString); } And my omrCheckEmail.php returns either "true" or "false" accordingly. Any help? Thanks, Fred 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.