我正在使用ajax,以便我可以從我的服務器讀取文件的內容。我正在調用一個函數,其中ajax是,在一個timer.And這是影響我的服務器。它是如果這是正確的做法,那有什麼問題? 請給予幾個sugestions,因爲我不知道它的問題是什麼。定時器中的Ajax影響我的服務器
我首先調用函數:「function(ctrl)」。
function get(ctrl){
var content;
content=ctrl.id;
var getTextUpdate= setInterval(function() {
readdocument();
}, 1200);
}
function readdocument() {
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("area").value=xmlhttp.responseText;
}
}
xmlhttp.open("GET","../user/test/read-text.php?user="+content,true);
xmlhttp.send();
}
這是讀text.php文件:
<?php
$rec_user=$_GET['user'];
echo($rec_user);
$chat = fopen($rec_user.".txt", "r") or die("Unable to open file!");
echo fread($chat,filesize($rec_user.".txt"));
fclose($chat);
?>
爲什麼不使用jQuery或一些已經在Js框架中構建的Ajax? –