Javascript 创建一个进度条,使用ajax和php检查数据状态
公众的想法是立即显示当前数据的状态。Javascript 创建一个进度条,使用ajax和php检查数据状态,javascript,php,jquery,ajax,progress-bar,Javascript,Php,Jquery,Ajax,Progress Bar,公众的想法是立即显示当前数据的状态。 我将举一个例子来说明这个想法 一个简单的例子: PHP: // target.php - this function will be called using ajax function immediately() { for ($i = 1; $i < 20; $i++) { echo $i; } } // this code will get the value of $i immediately $("#subm
我将举一个例子来说明这个想法 一个简单的例子: PHP:
// target.php - this function will be called using ajax
function immediately() {
for ($i = 1; $i < 20; $i++) {
echo $i;
}
}
// this code will get the value of $i immediately
$("#submit").click(function () {
$.ajax({
url: "pathToFile/immediately/", // Note: I'm use the style of a php framework to access to method.
success: function (data) {
$("#result").html(data);
}
});
return false;
});
$i = 1
Display it in the #result element.
$i = 2
Display it in the #result element.
and so on
我想要的是在每次更改中显示$I
的值
如下所示:
// target.php - this function will be called using ajax
function immediately() {
for ($i = 1; $i < 20; $i++) {
echo $i;
}
}
// this code will get the value of $i immediately
$("#submit").click(function () {
$.ajax({
url: "pathToFile/immediately/", // Note: I'm use the style of a php framework to access to method.
success: function (data) {
$("#result").html(data);
}
});
return false;
});
$i = 1
Display it in the #result element.
$i = 2
Display it in the #result element.
and so on
我不希望$I
等到访问最后一个值后再显示它。注意:前面的例子只是一个简单的例子来解释我的想法。我不明白这个问题,你想要$i保留它的价值吗?对于所有用户还是当前用户?实际上,现在可以看到,Ajax并不是为固定连接而设计的,你需要WebSocket或让js来处理(使用Ajax来提取数据库信息并使用js进行处理)@David:如果可能的话,我想要一个这样做的想法。它不像一些示例代码那么简单,你需要设置服务器来监听信息,但是这里有一个指向php类的链接,可能有一些信息可以设置你的服务器。如果不是谷歌的话。