Nasıl otomatik ajax ile refresh olmadan güncellenen veritabanı?

2 Cevap php

i'm new here. i just create a code which can read the data from mysql database. But when i add in new data inside databse, my php page cant updated own automatic. I want the page can updated automaticly withour press f5 button and refresh. Can anyone help me solve this?

Herhangi misstake alın?

<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>

2 Cevap

Siz veritabanında yeni veri olup olmadığını görmek için sayfanın tekrarlanan AJAX kontrol çeşit gerekir. SetTimeout veya setInterval kullanarak bunu yapabilirsiniz.

Örneğin

function CheckData() {
    List();
    setTimeout(CheckData, 10000);
}
setInterval(function() {
    List(); // your function
      // Do something every 2 seconds
}, 2000);

bu size yardımcı olacaktır jQuery işlevidir.