我在laravel 5.2上发出ajax请求后收到500(内部服务器错误)。
我可以看到有什么问题?
在某些时候,我看到有一个命令以tails开头,但找不到它。
感谢。
代码:
HTML:
<form role="form" id="Login" >
{{ csrf_field() }}
<label >Correo electronico: </label>
<input id="correo" type="email" class="form-control" name="email" placeholder="Enter email">
<id id="emailError"></id>
<label >Contraseña:</label>
<input id="password" type="password" class="form-control" name="password" placeholder="Enter password">
<id id="passwordError"></id>
<button type="button" class="btn btn-default" id="Submit" onclick="LogIn(event)" >Iniciar sesion</button>
</form>
JS:
function LogIn(event) {
event.preventDefault();
$.ajax({
type: 'post',
url: Login,
dataType: 'json',
data: {
email: $('#correo').val(),
password: $('#password').val(),
},
beforeSend: function()
{
$("#emailError").fadeOut();
$("#passwordError").fadeOut();
},
success: function (data) {
if (!data.success){
console.log(data);
if(typeof data.error.email !== 'undefined'){
$('#correo').css('border-color', 'red');
$('#emailError').fadeIn(10, function () {
$("#emailError").html(data.error.email);
})
}
if(typeof data.error.password !== 'undefined'){
$('#password').css('border-color', 'red');
$('#passwordError').fadeIn(10, function () {
$("#passwordError").html(data.error.password[0]);
})
}
}else{
console.log(data);
$('#LogIn').modal('hide');
}
}
});
}
控制器:
<?php
namespace App\Http\Controllers;
use App\Modals\Users;
use Illuminate\Http\Request;
use Validator;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use App\Modals\Users as user;
use Auth;
class UserController extends Controller
{
public function index()
{
return view('home');
}
/**
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function entrar (Request $request){
$validator= Validator::make($request->all(),[
'email' => 'required|email',
'password' => 'required|min:2',
]);
if ($validator->fails()){
return response()->json([
'success' => true,
'error' => $validator->errors()->toArray()
]);
}else{
return response()->json([
'success' =>true
]);
}
if (Auth::attempt(['email' => $request->email, 'password' => $request->password]))
{
return response()->json([
'success' => true
]);
}else
{
return response()->json([
'success' => false,
'error' => 'not login'
]);
}
}
}
日志:
POST http://localhost:8000/Entrar 500 (Internal Server Error) jquery.min.js:4
send @ jquery.min.js:4
ajax @ jquery.min.js:4
LogIn @ scripts.js:82
onclick @ VM18805:87