I have a Laravel app which is forwarding an URL to the Backbone:
urlContainer['userAjax'] = "{!! RoutingService::actionAjax('AccountController@getUserAjax') !!}";
And backbone gets it:
App.Models.User = bb.Model.extend({
url: urlContainer.userAjax,
});
Later on I call it like this:
var userLogged = new App.Models.User();
userLogged.fetch();
The problem I'm having is that the middleware I made in Laravel doesn't register it as AJAX call:
public function handle($request, Closure $next)
{
$parsedUrl = parse_url($request->url());
if (key_exists('path', $parsedUrl) && strpos($parsedUrl['path'], '-ajax') !== false && !$request->ajax()) {
return response('Bad request', 400);
}
return $next($request);
}
First two conditions are true, but the last one is not. It is behaving like it is not an AJAX request?