Laut der Methode im Internet wird immer noch ein Fehler von 500 angezeigt.
Router:
Route::get('/','Admin\BodyController@index');
Route::post('/ajax','Admin\BodyController@ajax');
ControllerBodyController:
public function index()
{
return view('Admin.Bodyadd');
}
public function ajax()
{
if(Request::ajax()){
return Response::json(Request::all());
}
}
Vorlage:
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="csrf-token" content="{{ csrf_token() }}" />
<title>Cate</title>
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.js"></script>
<script src="{{ asset('/jquery-1.11.3.min.js') }}"></script>
<script>
$(document).ready(function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('#ContentAdd').click(function(){
$.ajax({
type:"post",
url:"{{url('/ajax')}}",
data:{
'title':$('input[name=title]').val(),
'content':$('textarea[name=content]').val(),
},
dataType: 'JSON',
success: function(data){
console.log(data);
$('#postdata').html(data);
}
});
});
});
</script>
</head>
<body>
<p class="container">
<h1>Add Body</h1>
<hr>
<form>
<p class="form-group">
<label>标题</label>
<input type="text" class="form-control" name="title">
</p>
<p class="form-group">
<label>内容</label>
<textarea class="form-control" rows="3" name="content"></textarea>
</p>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<button type="submit" class="btn btn-default" id="ContentAdd">提交</button>
</form>
<p id="postdata"></p>
</p>
</body>
</html>
Es ist nicht wissenschaftlich~ Da stimmt etwas nicht! ! !
where is Error Exception,
where is Error Exception,
where is Error Exception.
看不懂╯ˍ╰