Hello all,
My first problem is that I would like to refresh a DIV tag on the same page using href onclick handler. Currently I can't seem to get this to work with the code I've developed.
My second problem is that once this works for one DIV I would like that same function to refresh another DIV on the same page using another href. The div ID's would be different of course and the page it calls it loads would also be different.
I'm sure my code is incorrect. I'm new to JavaScript and AJAX.
Thanks for any help on this one. Here's the code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function openConnection(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();// Firefox, Opera 8.0+, Safari
}catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
}catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("No AJAX!?");
return false;
}
}
}
//xmlHttp.onreadystatechange=function(){
function refreshIt(divID, MyPage) {
setTimeout('openConnection()', 1000);
document.getElementById(#divID).innerHTML=xmlHttp.responseText;
}
xmlHttp.open("GET",#MyPage,true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<a href="#" onClick="refreshIt(id1, 'page1.php')">Refresh</a>
<div id="id1">Default Page Text - Div One</div><br>
<a href="#" onClick="refreshIt(id2, 'page2.php')">Refresh</a>
<div id="id2">Default Page Text - Div Two</div>
</body>
</html>