Javascript 通过 http cmd 获取值

发布于 2024-09-04 19:49:17 字数 261 浏览 1 评论 0原文

我正在尝试从 url 中获取值: http://localhost:8080/bin/task_status?id=2&cmd=完成百分比 我不确定如何在 javascript (ajax) 命令中实际执行此操作,一旦页面加载,将每 0.5 秒调用一次。它使用AJAX内置的进度条来显示。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

無處可尋 2024-09-11 19:49:17

在 jQuery 中,您可以执行以下操作:

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

setInterval() 是一个内置 JavaScript 函数,每 X 毫秒重复一次命令,而 $.get() 执行 AJAX 请求。

正如 @Pointy 在评论中提到的,只有当页面也托管在 localhost:8080 上时,这才有效

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

倦话 2024-09-11 19:49:17

您始终可以使用 javascript 命令:location.href 并手动解析它。

您可以在此处找到演示。

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

you can find a demonstration over here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文