i want to add this headers
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
to my $.get jquery request
$('.wilayas').on('change', function(x) {
/*
$('.dayras').find('option')
.remove()
.end() */
alert(this.value)
$.get("{{ route('customer.auth.dayras') }}", {
data: this.value
},
function(data, status) {
alert(data);
$('.dayras').append(`
<option value="-">-</option>
`);
data.map(dd => {
$('.dayras').append(`
<option value="${dd.id}">${dd.dayra}</option>
`);
})
});
});
am getting the html response instead of json
The syntax of the jQuery ajax headers option :
$.ajax({
headers: {
"Accept": "text/json"
"Content-Type": "application/json"
}
...
...
});
The syntax of the jQuery ajax headers option set or overwrite with the beforeSend callback function :
$.ajax({
url: "{{ route('customer.auth.dayras') }}",
data: { foo: bar },
type: "GET",
beforeSend: function (jqXHR, settings) {
jqXHR.setRequestHeader("Accept", "text/json");
jqXHR.setRequestHeader("Content-Type", "application/json");
}
...
...
});