If you really need a unique ajax call for each counter value $, with data returning in div #result:
<script type="text/javascript">
$(document).ready(function(){
<?php
foreach($data['data'] as $data){
$count = $data['number'];
?>
$.ajax({
url: "process.php",
dataType: "html",
type: 'POST',
data: "items=<?php echo $count; ?>",
success: function(data){
$("#result").append(data);
}
});
<?php
}
?>
});
</script>
<div id="result"></div>
However, I highly recommend passing values as an array and having only one ajax call:
$count = array();
foreach($data['data'] as $data){
$count[] = $data['number'];
}
$datacount = implode('-',$count);
?>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
url: "process.php",
dataType: "html",
type: 'POST',
data: "items=<?php echo $datacount; ?>",
success: function(data){
$("#result").append(data);
}
});
});
</script>
<div id="result"></div>
On the server side in process.php you can explode('-',$_POST['items'])and then skip through them.
This is another way to do this ... It could be json_encoded or many other ways.
Fosco source
share