I am trying to get the currency from selected country name but ajax returns the value as undefined.
Ajax Code
$(document).on('change', '#country' ,function () {
var prod_id=$(this).val();
console.log(prod_id);
var a=$(this).parent();
var op="";
$.ajax({
type:'get',
url:'{!!URL::to('searchCurrency')!!}',
data:{'id':prod_id},
dataType:'json',//return data will be json
success:function(data){
console.log(data.currency);
// here price is column name in products table data.coln name
a.find('#currency').val(data.currency);
},
error:function(){}
});
});
$.ajaxSetup({ headers: { 'csrftoken' : '{{ csrf_token() }}' } });
Code in controller
$currency=Currency::select('currency')->where('country','=',$request->id)->pluck('currency')->first();
return response()->json($currency);