14-02-14, 10:21 AM
وهذا مع الاجكس
كود :
<?php
$file="wellcome.txt";
$current = file_get_contents($file); // اخذ محتوى النص الحالي
if(!empty($_GET['user']))
{
// هنا فحصنا هل يوجد مدخل ام صفخة عرض
// الان اذا اردت ان تضيف النص للمحتوى السابق
$current=$current.$_GET['user'];
file_put_contents($file, $current);
echo $current;
}
else
{
?>
<html>
<head>
<script>
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","newpage.php?user="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)" value=<?php echo "\"$current\"";?>>
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
<?php
}
?>