在ajax中显示来自mysql php的下一个值 [英] show next value from mysql php in ajax
问题描述
我有以下代码现在可以正常工作了,
I have the following Code which works good now,
<!DOCTYPE html>
<html>
<body>
<div id="one">
echo "data 1";
<input type="hidden" id="one" name ="one" value="'.$one.'">
</div>
<div id="two">
echo "data 1";
<input type="hidden" id="two" name="two" value="'.$one.'">
</div>
</body>
</html>
对于每个DIV,我都有数据1 2 3 ...更多来自MySQL php查询.因此,当Hidden Id = 1延迟一秒钟并显示下一个结果数据2时,直到我们再次将输入隐藏为1.全部来自数据库.自动地.我已经完成所有工作.
for each DIV I have data 1 2 3...more comes from MySQL php query. So, when the Hidden Id = one delay some second and show the next result data 2, until we get the input hidden to one again. that all come from database. automatically. I have all that working.
我能够使用Ajax显示数据,但是当我开始读取Input值并进行相应更改时.我有问题...
I am able to use ajax to show the data, but when i come to read the Input value and change accordingly. I have problem...
我已经尝试过了.
var value1 = $('one').attr( "value" ); //
var value2 = $('two').attr( "value" ); //
(function data() {
$.ajax({
url: 'data.php',
if (value1 == 'one') {
success: function(data) {
$('#one').html(data);
},
}
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(data, 5000);
}
});
})();
但是它似乎不起作用....
But it seems not working....
推荐答案
进行一些小修改可能有助于这项工作:
A couple of small modifications may help this work:
<!DOCTYPE html>
<html>
<body>
<div id="div-one">
<?php echo "data 1"; ?>;
<input type="hidden" id="one" name ="one" value="<?php $one; ?>;">
</div>
<div id="div-two">
<?php echo "data 2"; ?>;
<input type="hidden" id="two" name="two" value="<?php $two; ?>;">
</div>
</body>
</html>
JavaScript:
Javascript:
var value1 = $('#one').val();
var value2 = $('#two').val();
(function data() {
$.ajax({
url: 'data.php',
success: function(data) {
if (value1 == 'one') {
$('#div-one').html(data);
}
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(data, 5000);
}
});
})();
这篇关于在ajax中显示来自mysql php的下一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!