0

我们正在使用 Jquery UI 开发 ProgressBar。我们面临一些问题,即我们没有从 PHP 中获取值。我们无法创建一个可以将值返回到基于 Ajax 的代码的数字循环。

下面是我们的代码:

HTML

<!DOCTYPE html>
<html>
<head>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<style type="text/css">
  #bardivs {
   width:400px; /* or whatever the of the porgress bar is */
  /* 
   The position of #bardivs must be something other than
   static (the default) so that its children will be positioned
   relative to it.
   */
  position:relative;
  }
 #progresstext {
position:absolute;
top:0;
left:0;
}
 </style>
  <script>
  var url = "http://localhost/sample/data.php";
 $(function() {
  var progress = 0;
 //alert("some value" + value, value);
$("#progressbar").progressbar({ progress: 0 });
  setTimeout(updateProgress, 500);
 });
 function updateProgress() {
var progress;
$.get(url, function(data) {
    // data contains whatever that page returns     
    if (data < 100) {
        $("#progressbar").progressbar("option", "value", data);
        $("#progresstext").html("<p>    Loading...<p>");
        setTimeout(updateProgress, 500);
       } else {
        $("#progressbar")
          .progressbar("option", "value", 100);
    }

    }); 
  }
 </script>
</head>
<div id="bardivs">
<div id="progressbar"></div>
<div id="progresstext"></div>
</div>
</html>

我们不知道如何让 PHP 中的代码使用这个加载函数。它应该在一个循环中。

4

1 回答 1

0

没有这样progress: 0的,进度是衡量的value,你应该制作数据INT,因为它是字符串:

$("#progressbar").progressbar({ value: 0 });
    setTimeout(updateProgress, 500);
});
function updateProgress() {
    var progress;
    $.get(url, function(data) {
        // data contains whatever that page returns     
        if (data < 100) {
            $("#progressbar").progressbar({value: parseInt(data)});
            $("#progresstext").html("<p>    Loading...<p>");
            setTimeout(updateProgress, 500);
        } else {
            $("#progressbar").progressbar({value: 100});
        }
    }); 
}

在 php 中确保根据脚本更新进度

<?php
     $data = get_progress();
     echo (int)$data;
?>
于 2012-09-12T06:28:04.290 回答