<head> <script type="text/javascript"> var xmlHttp; function show_alert() { xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="alert_message.php"; alert(url); xmlHttp.onreadystatechange=stateChanged; xmlHttp.open("GET",url,true); xmlHttp.send(null); } function stateChanged() { if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { document.getElementById("txtHint").innerHTML = = xmlHttp.responseText; //alert(document.getElementById("txtHint").innerHTML); } } 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; } </script> </head> <form> <input type="button" value="button" onclick="show_alert();" style="margin-right:151px;" valign="top" class="button"> <form> <div id="txtHint"></div> <?php include("include/footer.php");?>
<?php include("../include/dbconnect.php"); ?> <?php $sql="SELECT * FROM alerts where created_by='demo' & status='1'"; $result=mysql_query($sql); // Start looping rows in mysql database. while($rows=mysql_fetch_array($result)){ ?> <table border='0' cellspacing='1' cellpadding='1' bgcolor='#ffffff' width="350" align='middle'> <tr> <td width="60">created On </td><td><? echo $rows['date_created']; ?></td> </tr> <tr> <td width="60">Message</td><td><? echo $rows['message']; ?></td> </tr> <?}?> </table> Can I call this file without button click, If I click on button click nothing comes up. help me, where I am wrong. Thanks, raizel
document.getElementById("txtHint").innerHTML = xmlHttp.responseText;