当我 $.ajax 从跨域请求执行下面的控制器的路由时,我得到一个空响应。当我取消注释 var_dump 行时,我得到一个带有数据的响应,否则我得到一个 404 响应并且 responsejson 对象未定义。非常感谢任何帮助。当我直接在浏览器中访问相同路由的 get 等效项时,我得到一个有效的 json 响应。
<?php
use App\Models\User;
class AuthenticationController extends \BaseController {
public function getLogin() {
return $this->postLogin();
}
public function postLogin() {
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
try {
$user = Sentry::authenticate($credentials, false);
if ($user) {
//var_dump(array('flash' => 'Authentication failed'));
//return Response::json(array('flash' => 'Authentication failed'), 401);
return $user->toJson();
}
} catch (Exception $e) {
return Response::json(array('flash' => 'Authentication failed'), 401);
}
}
public function getLogout() {
Sentry::logout();
return Response::json(array('flash' => 'Logged out'), 200);
//return Redirect::route('admin.login');
}
}