I'm not sure why none of these are not working. If I make two separate ajax calls, it works.
$('select[name="contact_id"]').on('change', function () {
var contact_id = $(this).val();
if (contact_id) {
$.ajax({
url: '/api/contact/getEmail/' + contact_id,
type: "GET",
dataType: "json",
beforeSend: function () {
$('#loader').css("visibility", "visible");
},
success: function (data) {
$('input[name="email"]').val(data);
},
complete: function () {
$('#loader').css("visibility", "hidden");
},
error : function(){
alert('Some error occurred!');
}
});
$.ajax({
url: '/api/contact/getPhone/' + contact_id,
type: "GET",
dataType: "json",
beforeSend: function () {
$('#loader').css("visibility", "visible");
},
success: function (data) {
$('input[name="number"]').val(data);
},
complete: function () {
$('#loader').css("visibility", "hidden");
},
error : function(){
alert('Some error occurred!');
}
});
} else {
$('select[name="contact_id"]').empty();
}
});