发现任何错误?
<script type="text/javascript">
function List(){
var ajaxRequest;
var selectedProduct = "";
var product = document.getElementById('product');
var output ="";
var k = 0;
// var name = new Array;
// var model = new Array;
var unitprice = new Array;
var queryString = new Array;
queryString = "&name=" + txtname + "&model=" + txtmodel + ;
ajaxRequest.open("GET", $productPrice + queryString, true);
ajaxRequest.send(null);
ajaxRequest.open("GET", $productPrice + queryString, true);
ajaxRequest.send(null);
<?php foreach ($productPrices as $price): ?>
name[k] = "<?php echo $price['Product']['txtname']; ?>";
model[k] = "<?php echo $price['Product']['txtmodel']; ?>";
k++;
<?php endforeach; ?>
k=0;
for (var i = 0; i < product.length; i++) {
k = product.options[i].value;
if (product.options[i].selected) {
output += '<tr>'+
'<td style="border-right: 0px; width:270px; text-align:center" id="ProductProduct'+k+'" name="data[Product][Product]['+k+']">'+name[i]+'</td>'+
'<td style="border-right: 0px; width:100px; text-align:left" id="ProductProduct'+k+'" name="data[Product][Product]['+k+']">'+model[i]+'</td>'+
'</tr>';
}
}
output = '<table style="width:500px; border: 0px;">'+output+'</table>';
document.getElementById('productTable').innerHTML = output;
}
</script>
答案 0 :(得分:1)
您需要在页面中进行某种重复的AJAX检查,以查看数据库中是否有新数据。您可以使用setTimeout或setInterval来执行此操作。
E.g。
function CheckData() {
List();
setTimeout(CheckData, 10000);
}
答案 1 :(得分:0)
setInterval(function() {
List(); // your function
// Do something every 2 seconds
}, 2000);
这是jquery函数,这对你有帮助。