weixin_33714884 2017-12-21 14:01 采纳率: 0%
浏览 25

骨干网没有通过AJAX

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?

  • 写回答

0条回答 默认 最新

    报告相同问题?