Посмотрите пожалуйста в return функции должен быть результат но в алерте обработчика ниже я получаю undefined Почему и что делать?
function change_bank_to_city(prop,bank_to_city_id,city_id,_check_city) {
var bank_id=$('#bank_id').val();
var data = {
url: '/admin/ajax/change-bank-to-city',
bank_id:bank_id,
prop:prop,
bank_to_city_id:bank_to_city_id,
city_id:city_id,
};
$.ajax({
url: data.url,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: data,
method: 'post',
async:false,
error:function (error) {
console.dir(error);
},
success:function(response){
alert(response)
return response.bank_to_city_id;
}
});
}
$('.check_city').on('change', function () {
var bank_to_city_id =$(this).parent('div').find('.bank_to_city_id').val()
var city_id =$(this).parent('div').find('.city_id').val()
var check_city = $(this).attr('id')
if($(this).is(':checked')){
var response = change_bank_to_city('add',null,city_id)
//поменять bank_to_city_id
alert(response)
alert(check_city)
alert($(this).parent('div').find('.bank_to_city_id').val())
$(this).parent('div').find('.bank_to_city_id').val(response.bank_to_city_id)
}
else{
change_bank_to_city('delete',bank_to_city_id,city_id,null)
}
});