2016-09-15 2 views
0

У меня есть проект MVC 3, который публикуется на сервере.Real Refresh/Update

Сценарий

Например, у меня есть функция для сохранения данных из (PC1) в (PC2).

Вполне возможно, что просмотр data(data in jqgrid) в (PC2) является open(open in page) пользователем, и он будет автоматически обновить или обновить страницу или jqgrid после (PC1) спасти данные?

Моя версия jqgrid - 4.3.3.

Надеюсь, вы, ребята, понимаете, что я имею в виду в своем посте. Опубликуйте отзывы, если голосуют. Благодарю.

Любая помощь будет принята.

ответ

0

Вы можете wonna использовать AJAX для выполнения такой работы, пожалуйста, прочитайте ниже

, если я понимаю, что вы имеете в виду, что вы wonna опрашивать сервер в режиме реального времени обновления на либо интервалы или что-то еще ...

вариант 1
Issue нормальный без гражданства Ajax вызова на сервер, а затем заставить сервер для хранения запроса в течение ограниченного времени [преодолеть сервер накладные]

Это также может быть указано как обратный аякс или комета.
Если вы не планируете использовать технологию websocket, я вряд ли подчеркиваю, что вы пытаетесь это сделать.

+0

Можете ли вы предоставить мне пример, если это возможно ?. Потому что я просто изучаю мир веб-программирования. –

0
if(isset($_GET['finite'])){ 
#declare time for a session 
$_SESSION['typing']=$reduce_browser_overhead=time(); 
#remember to close the session before entering the loop; 
#if u dont close, then the browser will not reload the same website untill the connection is close or satisfied 
session_write_close(); 
function loop(){ 
    #do this to access external variables ===> $reduce_browser_overhead; 
    global $con,$reduce_browser_overhead; 
    #explicitly check 2exit 
    #please do this to release mysql connection since they are in a loop 
    if($reduce_browser_overhead+4<time()){ 
     echo ' ';ob_flush();flush(); 
     if(connection_aborted()){ 
      #do some work here before you finally exit the connection 
      exit; 
     }$reduce_browser_overhead=time(); 
    } 
    #php prepare statement... 
    $looper=$con->prepare("SELECT ROW FROM TABLE WHERE ID=SOMETHING AND $_SESSION[typing]=SOME_ROW"); 
    #The statement above willcause the loop to work 
    #If a table had been update and table has not yet updated, this sql will detemin by the current time 
    #meaning that if the time[integer] of SOME_ROW is not equal to the time in the session variable, 
    #then it will let go to the client and then again it will continue looping untill the time in the 
    #SOME TABLE ROW changes.... 

    $looper->execute(); 
    $looper->store_result(); 
    if($looper->num_rows>0){ 
     sleep(2); 
     #do some work before looping again 
     loop(); 
     #you have to explicitly return to this loop to work as expected. 
     return; 
    }else{ 
     #send back data to the user or the client listening on the connection 
     session_start();$_SESSION['typing']=time();session_write_close(); 
     #update the session before finishing the request so that the next time the request comes, the time will be equal to the DBserver time in the row and hence causing the loop again and again => more like a cycle 
     echo 'After some time the server has received new data which is =>> '.$newdata; 
    } 
}loop(); 
exit; 

//In another file on in the same document as the php/your server file ==> do javascript below 
 
    //first issue a normal/stateless ajax request to the target server 
 
    $.ajax({ 
 
     //All optional but url required! 
 
     url:'abc.php?var_one=blabla', 
 
     cache:true,//whether to cache the requests 
 
     timeout:(1000*60)*20,//timeoutthe request 
 
     success:function(data){ 
 
      //if the server successfully completed the request 
 
      //do some work here with data returned 
 
     }, 
 
     error:function(){ 
 
      //if the server return an error 
 
      //do more work around 
 
      //or call the function again 
 
     } 
 
    });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

+0

Почему есть код для PHP, но я не просил об этом? –