我正在開發一個應用程序與laravel 5,並通過AJAX發送信息,但如果我想顯示由FormRequest生成的錯誤消息?因爲在網絡瀏覽器控制檯 - >預覽可以看到錯誤消息請求後顯示消息錯誤AJAX Laravel 5.1
我FormRequest的createRequest
<?php
namespace Cinema\Http\Requests;
use Cinema\Http\Requests\Request;
class CreateRequest extends Request
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'genre' => 'required',
];
}
}
我的控制器:
<?php
namespace Cinema\Http\Controllers;
use Illuminate\Http\Request;
use Cinema\Http\Requests;
use Cinema\Http\Requests\CreateRequest;
use Cinema\Http\Controllers\Controller;
class GenreController extends Controller
{
public function store(CreateRequest $request)
{
if ($request->ajax())
{
return response()->json([
'petition' => $request->all()
],200);
}
}
}
我的請願書AJAX:
$("#registro").click(function(){
var data = $("#genre").val();
var route = "http://localhost:8000/genero";
var token = document.getElementById('token').value
$.ajax({
url: route,
headers: {'X-CSRF-TOKEN': token},
type: 'POST',
dataType: 'json',
data: {data : data},
});
});
我可以在控制檯中看到消息錯誤:
但是如何顯示? ,謝謝:d