Actually i am sending ajax requests with in a interval of 4-5 seconds to update a digital display table.
- Should i use ajax GET or POST
- What is ajax cache:true/false
- If i populate DOM elements(some are marque) after each ajax call(in 4 seconds) then will it affect performance
My code is something like :
<table>
<?php for(i=0; $i<=10; $i++) { ?>
<tr>
<td><span id="span-<?php echo $i;?>-1></span></td>
<td><span id="span-<?php echo $i;?>-2>></span></td>
<td><span id="span-<?php echo $i;?>-2>></span></td>
<td><marque id="td-<?php echo $i;?>-4>></marque></td>
</tr>
<?php } ?>
<script>
$(document).ready(function() {
autoRefresh_div();
function autoRefresh_div()
{
dataString = 'x=fetchdata';
$.ajax({
type: "POST",
url: "display_ajax.php",
data:dataString,
dataType: 'json',
success: function(result){
$.each(result, function( index, value ) {
if (value['status']==1) {
$('#span-'+index+'-1').html(value['status']);
$('#span'+index+'-3').html(value['name']);
$('#span-'+index+'-4').html(value['type']);
$('#td-'+index+'-5').html(value['des']);
} else {
$('#span-'+index+'-2').html('N/A');
}
});
},
complete: function() {
setTimeout(autoRefresh_div, 4000);
}
});
}
});
</script>
And array returned as json from server is like
array
(
0 => array('status'=>2),
1 => array('status'=>1,'name'=>'xyz','type'=>'t1','des'=>'jfhj.....'),
2 => array('status'=>1,'name'=>'abc','type'=>'t2','des'=>'llll.....'),
3 => array('status'=>1,'name'=>'def','type'=>'t1','des'=>'ffhj.....'),
4 => array('status'=>2),
5 => array('status'=>1,'name'=>'jkl','type'=>'t4','des'=>'llol.....'),
6 => array('status'=>2),
7 => array('status'=>1,'name'=>'aaa','type'=>'t3','des'=>'lojl.....'),
8 => array('status'=>1,'name'=>'bbb','type'=>'t4','des'=>'loll.....'),
9 => array('status'=>1,'name'=>'lll','type'=>'t1','des'=>'lhol.....'),
)