www.webdeveloper.com
Results 1 to 2 of 2

Thread: Start and stop icon

  1. #1
    Join Date
    May 2013
    Posts
    1

    Start and stop icon

    Hi. I am not a javascript developer.. I have this page that call a servlet every x number of seconds.

    Code:
    <script type="text/javascript">
    	var defaultDelay = 2000;
    	var maxDelay = 64000;
    	var reconnectDelay = defaultDelay;
    
        function reconnect (url) {
            var request = $.ajax({
                url: url,
                type: "GET",
                dataType: "text"
            });
    
    		request.success(function(msg) {
    			document.getElementById("monitor").innerHTML = document.getElementById("monitor").innerHTML + msg;
    			document.getElementById("connection").innerHTML = "Connected";
    			reconnectDelay = defaultDelay;
    			setTimeout(function() { reconnect(url); }, reconnectDelay);
            });
    
    		request.error(function(msg) {
    			document.getElementById("connection").innerHTML = "Unconnected";
    			if (reconnectDelay < maxDelay) {
    				reconnectDelay = reconnectDelay * 2;
    			}
    			setTimeout(function() { reconnect(url); }, reconnectDelay);
    		});
        }
    
        function go() {
            var url = document.URL;
            url = url.substring(0, url.lastIndexOf('/'));
            url = url.substring(0, url.lastIndexOf('/'));
            url = url + '/monitor';
    
            reconnect(url);
        }
    
        $(document).ready(go());
    </script>
    <p id="connection">Connected</p>
    <hr/>
    <ul id="monitor">
    </ul>
    I would like to create a icon to start and stop this function.
    So when the icon is pressed the page will call the servlet x number of senconds until the icon is pressed again... or a timeout has occurred. i.e. 5 min

    Thanks

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Code:
    <button onclick=go() >update</button>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles