php - dynamically loading javascript fails, but innerHTML does -
i've wrote script in javascript file , innerhtml refreshes time time
setinterval(activeload,1000); function activeload() { activediv.innerhtml=""; scriptsrc.src="http://localhost/mypro/pro/activeuser.php"; for(i=0;i<=activeuser.length;i++) { if(activeuser[i]!=null) activediv.innerhtml+="<p onclick='dial(' " + activeuser[i] +" ' )'> " + activeuser[i] +"</p><br>"; } scriptsrc.src=''; }
in above script, innerhtml modifying, src attribute of script not changing...
js file loaded is
<script src="http://localhost/mypro/pro/activeuser.php" id="scriptsrc" type="application/javascript"></script>
this php file refreshes every 5 secs , accurate in information.
need in loading javascript perfectly
although it's not clear me want array comes activeuser.php
, seems ajax best bet bring in page on regular interval. here basic example of ajax call using jquery:
<script src="jquery-2.1.4.min.js"></script> <script> setinterval(function() { $.ajax("/mypro/pro/activeuser.php").done(function(data) { console.log(data); }); }, 5000); </script>
the way works $.ajax()
call request activeuser.php
server. file delivered, anonymous function inside of .done()
called. function has 1 parameter, i've named data
, contains contents of activeuser.php
.
ajax convenient way request data server without reloading entire current page when data delivered browser.
Comments
Post a Comment