samedi 27 juin 2015

Ajax in timer is affecting my server

I am using ajax so that i can read the content of a file from my server .I am calling a function where ajax is , in a timer.And this is affecting my server .It is crashing.If this is the correct way to do it , what's wrong? Please give a few sugestions,because i don't know what its problem is.

I am calling first the function:"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();

                        } 

Here it is the read-text.php file:

<?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);

?>

Aucun commentaire:

Enregistrer un commentaire