I have this ajax call
<script>
function add(serviceId){
$.ajax({
url: "<?php echo Yii::app()->createUrl($bus->url.'/serAjax'); ?>",
type: "POST",
data: {"serviceId": serviceId},
success: function(result){
$("#services").append(result);
},
error: function (){
alert('Error');
}
});
}
the ajax calls this page
if(isset($_POST['serviceId']))
{
$serviceId = $_POST['serviceId'];
}
$service = Services::model()->findByPk($serviceId);
$all = array();
$ids = array();
//add services to array
array_push($all, $service->title);
array_push($ids, $service->id);
Yii::app()->session['serviceId'] = $ids;
foreach ($all as $a){
echo '<li class="list-group-item">'.$a.'</li>';
}
A user can click multiple service options and every time they do this ajax is called. Now what I want to happen is every time a user add a service, it stores the service ids in the $ids = array(); But whats happening is that every time the ajax call is made, it empties out the array only leaving the last selected service. I need it to retain all the ids.