I am a new bee to AJAX. i want to synchronize text box of one client and the text box of another client that is contents typed by one client in his text box should be viewed by another client in his text box. I wrote a code to write the contents of text box of clients to a single file and to load the contents of the file at the same time to the text boxes of clients but the problem was only loading from file to text box happens and it is not writing the text box values to the file.
my code is:
index.php
<html>
<head>
<script type="text/javascript">
function fun1()
{
var a;
if (window.XMLHttpRequest)
{
a=new XMLHttpRequest();
}
else
{
a=new ActiveXObject("Microsoft.XMLHTTP");
}
name=encodeURIComponent(document.getElementById("name").value);
a.open("GET","quickstart.php?name=" + name,true);
a.onreadystatechange=function()
{
document.getElementById("name").value=a.responseText;
}
a.open("POST","123.txt",true);
a.send();
} // fun1() close
</script>
</head>
<body>
<input type="text" id="name" onkeyup="fun1()" />
</body>
</html>
quikstart.php
<?php
header('Content-Type: text/xml');
echo '<response>';
$name=$_GET['name'];
$file=fopen("123.txt","w");
fwrite($file, $name);
fclose($file);
echo '</response>';
?>