php - How to use file_get_contents on loop? -


i'm trying use file_get_contents on loop, in order fetch json string url continuously (every second). , need store result javascript variable. here approach, didn't result this. page showed me nothing endless loading.

<?php     set_time_limit(0);     while(true)     {     $jsoncontent=file_get_contents('http://megarkarsa.com/gpsjson.php');     echo $jsoncontent;     sleep(10);     }  ?> 

and here javascript code.

setinterval(function(){         var jsonupdpostdata = <?php echo $jsoncontent; ?>; }, 100); 

what should make work? suggestion appreciated.

you can make work way:

getcontent.php

<?php echo file_get_contents('http://megarkarsa.com/gpsjson.php'); 

xxxx.js

setinterval(function(){   var xmlhttp = new xmlhttprequest();    xmlhttp.onreadystatechange = function() {     if (xmlhttp.readystate == 4) {       alert(xmlhttp.responsetext); // contains new file contents     }   }    xmlhttp.open('get', 'getcontent.php');   xmlhttp.send(); }, 100); 

Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

html - Outlook 2010 Anchor (url/address/link) -