Here is what I want to do:
1. have the javascript check to see if a flag is changed in a DB and change a div if it is set to true.2. check this flag every second.
No big deal. I can get it to work great in firefox and opera but not IE7. In IE, it runs the function once and looks like it quits before it runs setTimeout. Here are my three scripts for the Ajax:
main page:
<?php
require_once(“vars/conn.php”);
// get userID with mysql_insert_id() when the user submits name.
// pass the userID to this script to use in AJAX
$userID = 1;
?>
<html>
<head>
<script language=”javascript” type=”text/javascript” src=”js/AJAXfunction.js”></script>
<script language=”javascript” type=”text/javascript”>
function checkEmailFlag(){
showCount(document.forms[0].userID.value);
setTimeout(“checkEmailFlag()”,1000);
}
</script>
</head>
<body>
<form>
<input type=”hidden” name=”userID” value=”<?php echo $userID ?>”>
<div id=”txtHint”><input type=”text” id=”txt” value=””></div>
</form>
<input type=”button” name=”testButton” value=”Click Me” onclick=”javascript:alert(‘hello’)”>
<script>checkEmailFlag()</script>
</body>
</html>
Ajax page:
var xmlHttp
function showCount(str){
//alert(str);
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null){
alert (“Your browser does not support AJAX!”);
return;
}
var url=”getcount.php”;
url=url+”?q=”+str;
xmlHttp.onreadystatechange=flagChanged;
xmlHttp.open(“GET”,url,true);
xmlHttp.send(null);
}
function flagChanged(){
if (xmlHttp.readyState==4){
document.getElementById(“txtHint”).innerHTML=xmlHttp.responseText;
}
}
function GetXmlHttpObject(){
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
xmlHttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
}
return xmlHttp;
}
getcount.php:
<?php
require_once(“vars/conn.php”);
//get the current userID
$count = $_GET[‘q’];
//get flag from DB
$s = “SELECT * FROM user WHERE userID = $count”;
$q = mysql_query($s);
$r = mysql_fetch_assoc($q);
// create vars
foreach($r as $key=>$val){
$$key = $val;
}
if($flag){
echo “<input type=”text” id=”txt” value=”Welcome, $name” readonly>”;
}else{
echo “<input type=”text” id=”txt” value=”Waiting…” readonly>”;
}
?>
This is textbook Ajax and works exactly like I want in firefox and opera. I need to know what I need to change to get it to work in IE7 too. Thanks