Request::ajax() = True when:
headers:{
"X-Requested-With" : "XMLHttpRequest"
},
Request::wantsJson() = True when:
Note: laravel looks for “json” in the first accept parameter.
headers:{
"Accept" : "application/json"
}
Both are true if
headers:{
"X-Requested-With" : "XMLHttpRequest",
"Accept" : "application/json"
}
Global jQuery setup
This will add the proper headers to all jQuery$.ajax $.get $.post calls in your app.
$.ajaxSetup({ headers: { "X-Requested-With" : "XMLHttpRequest", accept: "application/json" } });
The headers can be overridden and appended in the indivdual calls.
Global Angular setup
This will add the proper headers to all Angular http calls in your app.
app.config(['$httpProvider', function($httpProvider){ $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest'; $httpProvider.defaults.headers.common["accept"] = 'application/json'; }]);