suresh anugandula
calling setInterval() on onclick event
0 Answer(s)      4 years and 4 months ago
Posted in : Ajax

Hi all,

I am trying to call setInterval() on onclick event. But it is executing the code only once. Following is my code.

<script type="text/javascript" language="javascript">
            var xmlHttp;
            function postRequest() {        
                    if (typeof XMLHttpRequest != "undefined"){

                            xmlHttp= new XMLHttpRequest();
                        }else if (window.ActiveXObject){

                            xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
                        if (xmlHttp==null){
                            alert ("Browser does not support XMLHTTP Request")
                        var url="/AutoDialer/two.jsp";
                        xmlHttp.onreadystatechange = stateChange;
              "GET", url, true);
             function stateChange(){
                        if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
             function send(){       
            // alert("send");       
                var a=setInterval(postRequest(),3000);
                //alert(a+"=: "+a);                             


  <div id="one" onClick="send();"><a href=""><span class="hyper">On Call Report</span></a></div>


Here this code is executing two.jsp only once. And ready state is always 1. Please help me in resolving this problem.

View Answers

Related Tutorials/Questions & Answers: