【问题标题】:jquery get data using jquery.loadjquery 使用 jquery.load 获取数据
【发布时间】:2013-08-16 20:44:04
【问题描述】:

我有一个与我之前的问题类似的问题,但现在不同了

jquery : progress bar show in html

  var auto_refresh = setInterval(
   function ()
  {
     $('#battery').load('https=://localhost/userinfo/battery_level/');

 }, 10000);

我不想加载 div ...我想得到结果并想在这里显示在我的进度条中

 $('.demo-progress').progress(data);

我在这里得到一个值“10”

想做这样的事情

 var auto_refresh = setInterval(
   function ()
  {
    var data =  $('#battery').load('https=://localhost/userinfo/battery_level/');

 }, 10000);
      $('.demo-progress').progress(data);

【问题讨论】:

  • batter_level 文件中有什么内容?
  • 它是一个控制器名称,它只发送值...例如 20

标签: php javascript jquery css ajax


【解决方案1】:

试试这个:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" type="text/css" rel="Stylesheet" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script>
        $(function () {
            $("#progressbar").progressbar({ max: 100, value: 10 });
            $("#twenty").click(function () { loadFile("20"); });
            $("#fifty").click(function () { loadFile("55"); });
            $("#eighty").click(function () { loadFile("80"); });
        });


        function loadFile(file) {
            $.get(file + ".txt", function (data) {
                var value = parseInt(data, 10);
                $('#progressbar').progressbar("option", "value", value);
            });
        }
    </script>
</head>
<body>
    <div id="progressbar">
    </div>
    <input type="button" id="twenty" value="Load to 20%" />
    <input type="button" id="fifty" value="Load to 50%" />
    <input type="button" id="eighty" value="Load to 80%" />
</body>
</html>

来自 jquery 页面:

此方法 (.load) 是从服务器获取数据的最简单方法。 它大致相当于 $.get(url, data, success) 除了它 是一种方法而不是全局函数,它有一个隐含的 回调函数。

我之所以使用.get是因为最后一部分,隐式回调函数,它让我知道函数何时结束,然后我可以更新进度条。

【讨论】:

  • 我不想使用 get .. 因为我想在不刷新页面的情况下显示实时数据 .. 我认为通过使用你的代码我必须刷新页面以获得结果
  • 为什么不先试试呢?这不会刷新页面。
  • oooookkk 让我试试
  • 不,不工作......好吧,我认为你应该给一些时间间隔......不要你......但它没有给我没有刷新的价值
  • 你确定你正确调用了 .progressbar 方法吗?您在另一个问题$(".demo-progress").progressbar("option", "value", 50); 中有所不同,所以也许它的$(".demo-progress").progressbar("option", "value", data);
猜你喜欢
  • 2014-03-11
  • 1970-01-01
  • 2019-08-22
  • 2012-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-31
  • 2014-02-21
相关资源
最近更新 更多