繁体   English   中英

jQuery使用jquery.load获取数据

[英]jquery get data using jquery.load

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

jQuery的:进度条显示在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);

尝试这个:

<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的原因是由于最后一部分是隐式回调函数,它使我知道该函数何时结束,然后可以更新进度条。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM