views:

27

answers:

2

Hello, I am trying to grab a value from a url: http://localhost:8080/bin/task_status?id=2&cmd=percent_done I am unsure how to actually do this within a javascript (ajax) command that once the page has been loaded will be called every .5 seconds. It is using the AJAX built in progress bar to display.

+1  A: 

you can always use the javascript command: location.href and parse it manually.

you can find a demonstration over here.

dig
The problem is that the value isn't actually in the url. The value is displayed or returned (not sure which to tell the truth) based on that url because it uses the cmd to get the value which would be between 0-100.
Craig
+1  A: 

In jQuery you can do:

setInterval(function() {
    $.get('http://localhost:8080/bin/task_status?id=2&cmd=percent_done', function(data) {
        // data contains whatever that page returns
    });
}, 500);

setInterval() is a built-in JavaScript function that repeats a command every X milliseconds, and $.get() performs an AJAX request.

As @Pointy mentioned in a comment, this will work only if the page is also hosted on localhost:8080

VoteyDisciple