ajax - Using iframe for "long polling" withouth causing flashing browser -


i need check if commands written txt file in order update 3d window inside web browser. known "push" technique or long polling notify client. browser has be internet explorer bit limited.

i have come solution using hidden iframe calls php script reloads every second check txt file.

<iframe noresize scrolling="no" frameborder="0" name="loader" src="loader.php">   

the loader.php this:

//check txt , commands <body onload="window.setinterval('location.reload()',1000);"></body> 

the problem see every second in web browser reload button flashes. although window not flashing, button, still find bit annoying.

is there better solution problem, still compatible ie?

finally, after many tries managed make work consider optimal standard solution: long polling ajax solution. gives many problems in ie7, paste codes below.

first php file, reads txt , echoes json text.

<?php $commandfile = fopen("./command.txt","r");  fseek($commandfile, 0); $command = fscanf($commandfile, "%s\n"); //reads command fclose($commandfile);  if($command[0] != "") {   $commandfile = fopen("./command.txt","w"); //delete first line   fclose(commandfile);       echo json_encode($command[0]);   } ?> 

now, html main page needs mechanism call function recursively launchs php file , checks answer. function this.

<head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"></script> </head> <body> <script type="text/javascript"> function longpolling() {     $.ajaxsetup({ cache: false }); //this line key work under internet explorer     $.ajax({                         type: "get",             url: "loader.php",         datatype: 'json',         async: true,          success: function(response){                                             if(response!=""){                 sendcommand(response);  //could other function                        }             //longpolling();             settimeout(longpolling,1000);                 },         error: function(){             //longpolling();                         settimeout(longpolling,1000);         }             });     };  $(document).ready(function(){   /*waits till whole page loads*/     longpolling(); /*start initial request*/ }); </script>  </body> 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -