I created a php page that get data from a table from Database then html page that get the php file and refresh it using AJAX, But I need to put the php code in html file and refresh the code, this is my code that refresh a div tag from an external file :
<script>
function Ajax(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Oops!");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('ReloadThis').innerHTML=xmlHttp.responseText;
setTimeout('Ajax()',2000);
}
}
xmlHttp.open("GET","see.php",true);
xmlHttp.send(null);
}
window.onload=function(){
setTimeout('Ajax()',2000);
}
</script>
<div id="ReloadThis"></div>
but I want to refresh a specific PHP code in the same page for example:
<script>
function Ajax(){
var xmlHttp;
try{
xmlHttp=new XMLHttpRequest();
}
catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
alert("Oops!");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
document.getElementById('ReloadThis').innerHTML=xmlHttp.responseText;
setTimeout('Ajax()',2000);
}
}
xmlHttp.open("GET","see.php",true);
xmlHttp.send(null);
}
window.onload=function(){
setTimeout('Ajax()',2000);
}
</script>
<?php
$txt = $_POST['text'];
$sql = mysql_query("SELECT * FROM `table`WHERE `id` = '$txt'");
while($fetch = mysql_fetch_array($sql)){
$names = $fetch['name'];
echo $names;
echo "</br>";
}
?>
How can I refresh the php code while it is in the same page?