【发布时间】:2019-03-25 09:57:35
【问题描述】:
我正在使用 Laravel 5.7 和 angularjs 构建应用程序。我想通过ajax进行授权。登录和注册工作正常,但重置密码工作不正确。问题是没有错误或成功回调消息。我注意到我的请求转到了正确的路线,但随后它将我重定向到了我的主页。所以在回应中,我总是得到我的索引页。
默认情况下,laravel 会抛出错误“我们找不到具有该电子邮件地址的用户”。但是如果你使用ajax,它不会抛出任何东西,我也不知道问题出在哪里,因为登录和注册都会成功抛出错误。
//HTML template
<form ng-submit="auth('{{ route('password.email') }}')">
@csrf
<div>
<div>Enter your e-mail</div>
<div>We will send you an email with a link to create a new password.
</div>
<div ng-repeat="error in authErrors.errors">@{{error[0]}}</div>
</div>
<div>
<label for="email">{{ __('E-Mail Address') }}</label>
<input name="email" ng-model="authInfo.email" type="email" required>
</div>
<button type="submit" name="submit">{{ __('Send Password Reset Link') }}</button>
</form>
//JS
$scope.authInfo = {
name: null,
email: null,
password: null,
passwordConfirmation: null,
remember: false
}
$scope.authErrors = {};
$scope.auth = function(route){
$http({
method: 'POST',
url: route,
data: $scope.authInfo
}).then(function(response) {
console.log($scope.authInfo);
console.log(response);
}, function(response) {
console.log($scope.authInfo);
$scope.authErrors = response.data;
console.log(response.data)
})
}
身份验证控制器都是默认的。
我也在 clear 项目上测试了 ajax 并得到了相同的结果。
如果我不发送电子邮件作为数据,它会抛出一个错误,即没有电子邮件。但如果我发送一封电子邮件,我会得到重定向。
我希望获得与注册和登录功能相同的结果。
有什么建议可以解决这个问题吗?
【问题讨论】:
标签: angularjs laravel laravel-5