I want to apply the getStatus
function right here:
function getStatus(id)
{
$.ajax({
method: "POST",
url: '<?php echo base_url('marketplace/get_store_status'); ?>/'+id,
dataType: 'json',
success: function(data){
return data.status;
}
});
}
Into this function right here:
$('#store-status').click(function() {
var id = getStatus(<?php echo $vendor->store_id; ?>);
if (id == 1) {
$('#btn-status')
.removeClass('btn-danger')
.addClass('btn-primary')
.text('Activate');
} else {
$('#btn-status')
.removeClass('btn-primary')
.addClass('btn-danger')
.text('Deactivate');
}
console.log(id);
$('#modal-status').modal('show');
});
But when i log the id
variable in the element click function into the console, it shows undefined
.
But when i log the success data from the getStatus function itself, it shows the correct data. What am I doing wrong in my code?