Hi to all
The following scrips work as expected in Firefox (no surprise there) but not in IE8 (need i say more). Any changes to the js script as in alerts etc and updates to the db show immediately in FF but in IE it shows the results when the page loads and on the click event but any updates or changes do not reflect. Yet if I leave the page open for some time it will sometimes work in IE? I have tried and tested the XMLHttpRequest with various ActiveXObject parameters and always get a result. Googling only got me a hit that said IE had issues with div tags and ajax so hence the alert for the response but still nothing.
Totally baffled with this one and very interested to see if any one has a solution.
Here's hoping.
Cheers.
function getXMLHttp(){
var xmlHttp
try{
//Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}catch(e){
//Internet Explorer
try{
xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
}catch(e){
try{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("Your browser does not support AJAX!")
return false;
}
}
}
return xmlHttp;
}
function MakeRequest(){
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function(){
if(xmlHttp.readyState==4){
HandleResponse(xmlHttp.responseText);
}
}
xmlHttp.open("GET", "script.php", true);
xmlHttp.send(null);
}
function HandleResponse(response){
alert(response);
}
<?php
ob_start();
$conn=mysql_connect('localhost','******','******');
$db=mysql_select_db('test',$conn);
$sql="SELECT * FROM tester";
$result=mysql_query($sql)or die(mysql_error());
while($rows=mysql_fetch_assoc($result)){
$data[]=$rows['data'];
}
print_r($data);
flush();
ob_flush();
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="js.js"></script>
<script type="text/javascript">
function ajx(){
return MakeRequest();
}
</script>
<title>Untitled Document</title>
</head>
<body>
<button onclick="ajx()">Submit</button>
</body>
CREATE TABLE IF NOT EXISTS `tester` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`data` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;