Jump to content

Works in IE8, but not in Safari!


FredFogg

Recommended Posts

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.