开发者

Javascript grab value via http cmd

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 buil开发者_如何转开发t in progress bar to display.


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


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

you can find a demonstration over here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜