0

i've wrote a script in which javascript file and innerHTML refreshes time to 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 the above script, innerHTML is modifying, but src attribute of script is not changing...
the 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 and is accurate in information.
need some help in loading the javascript perfectly

7
  • 1
    What is the value of scriptsrc? More importantly, what are you trying to do here? Commented Nov 1, 2015 at 13:42
  • var scriptsrc=document.querySelector('#id_of_script_tag'); Commented Nov 1, 2015 at 14:37
  • im trying to represent some live data to user...so im using setInterval for frequent updating of information Commented Nov 1, 2015 at 14:38
  • Why do you want to change the script source to accomplish that? Commented Nov 1, 2015 at 15:40
  • as the script src is php which gives updated array at every interval of time. Im not actually changing script src, but reloading the same script again, please help Commented Nov 2, 2015 at 14:02

1 Answer 1

1

Although it's not clear to me what you want to do with the array that comes from activeuser.php, it seems like AJAX will be your best bet to bring it in to your page on a regular interval. Here is a basic example of an 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 it works is that the $.ajax() call will request activeuser.php from the server. As soon as the file is delivered, the anonymous function inside of .done() will be called. That function has one parameter, which I've named data, that contains the contents of activeuser.php.

AJAX is a very convenient way to request data from the server without reloading the entire current page when the data is delivered to the browser.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you so much,but i got an plain text in result ["user2","user1","user3"]. how to convert this as an array?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.