javascript - getting connection reset after sending a jquery ajax $.post -


i making game lobby php, jquery, ajax. have php echo string jquery loop sends ajax $.post's page check , see if 1 joined players game, if new users online , current games join. if there fill div's on page new data.

here loop

<script>     $(function() {         getpage = function() {             // gets current games users trying start             $.post("lobbyclasses.php",             {                 lobbyrequest: "getgames",             },             function(data, status){                 if(status == "success"){                     $("#joingamecontainer").html(data);                     // gets online users , puts themin div onlineusers                     $.post("lobbyclasses.php",                     {                         lobbyrequest: "getonlineusers",                     },                     function(data, status){                         if(status == "success"){                             $("#onlineusers").html(data);                             // start again;                             settimeout(function(){                                 getpage();                             }, 5000);                         }else{                             // online users failed start loop again                             $("#onlineusers").html("failed...");                             settimeout(function(){                                 getpage();                             }, 5000);                          }                     });                 }else{                     //get games failed start loop again                     $("#joingamecontainer").html("failed...");                     settimeout(function(){                                 getpage();                     }, 5000);                 }             });         }         getpage();     });     </script> 

the problem loop works , others browser(chrome , firefox) stall , give error (connection reset in firefox)(no data returned in chrome) thought nesting post request might , did still happens time time. happens lot more when send post different page such following ....

$("#makegame").click(function(){     getgame = function() {         $("#scripts").html("getting data...");         $("#onlineusers").html("getting data...");         $("#joingamecontainer").html("getting data...");         $("#gamecontainer").html("getting data...");         //alert("newgame clicked.");         $.post("cardgameclasses.php",                 {                     gamerequest: "makegame",                 },                 function(data, status){                     // code stalls here , dose nothing browser error happens                      //alert("data: " + data + "\nstatus: " + status);                     if(status == "success"){                         $("#scripts").html(data);                     }else{                         $("#scripts").html("failed...");                         settimeout(function(){                             getgame();                         }, 5000);                     }                 });     }     getgame(); 

so thought replacing loop text sending post , did little bit on occasion still browser error connection reset. not sure doing wrong please help.

i figured out going on code php allows many post vars single page prevent denial of service attacks. sending many posts. realized every thing trying update ajax updated single post instead of 4 nested posts. processing of data can done on server side. if making several posts 1 page doing wrong. proper code this:

    function mytimer() {     $.post("lobbyclasses.php",     {         lobbyrequest: "getcontent1",     },     function(data, status){         if(status == "success"){             $("#lobbycontent").html(data);         }else{             $("#lobbycontent").html("failed...");         }     }); } mytimer(); var myvar = setinterval(function(){ mytimer() }, 5000);  function mystopfunction() {     clearinterval(myvar); } 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -