[英]How to automatically send new record to mysql row every minute in php
[英]add new row every second via php mysql jquery
我想每秒将新行添加到div.list中,而不删除或刷新最后一行或刷新页面。 我将如何实现这一目标?
到目前为止,这是我的代码(只需将test2.php的内容替换为xx即可使用):
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript">
jQuery(function($){
setInterval(function(){
$.get( 'http://example.com/php/test2.php', function(newRowCount){
$('#rowcounter').html( newRowCount );
});
},1000); //
});
</script>
</head>
<body>
<div id="log">
</div>
<p>There are <span id='rowcounter'>xx</span> rows in the DB.</p>
</body>
</html>
这是我页面中的代码:
<div class="list">
<div>new row1</div>
<div>new row2</div>
<div>new row3</div>
<div>new row4</div>
.
.
.
</div>
您可以将所需内容添加到列表中,而无需删除最后一行
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript">
jQuery(function($){
setInterval(function(){
$.get( 'http://example.com/php/test2.php', function(newRowCount){
$('#rowcounter').append( newRowCount );
});
},1000); //
});
</script>
</head>
<body>
<div id="log">
</div>
<p>There are <span id='rowcounter'>xx</span> rows in the DB.</p>
</body>
</html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
<script type="text/javascript">
jQuery(function($){
setInterval(function(){
$.ajax({
url: "http://example.com/php/test2.php",
type: "GET",
data: {id : $('#list div').length},
dataType: "html",
success: function( data ) {
$('#list').append( data );
$('#rowcounter').html( $('#list div').length );
}
});
},1000);
});
</script>
</head>
<body>
<div id="list">
</div>
<p>There are <span id="rowcounter">0</span> rows in the DB.</p>
</body>
</html>
<?php
//Listing: http://example.com/php/test2.php
$id = isset($_GET['id'])?$_GET['id']:0;
echo '<div>new row'.$id.'</div>';
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.