Rumah > Soal Jawab > teks badan
Mengikut kaedah di Internet, ia masih mendapat ralat 500.
Penghala:
Route::get('/','Admin\BodyController@index');
Route::post('/ajax','Admin\BodyController@ajax');
Pengawal Badan Pengawal:
public function index()
{
return view('Admin.Bodyadd');
}
public function ajax()
{
if(Request::ajax()){
return Response::json(Request::all());
}
}
Templat:
<!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>
Ia tidak saintifik~ Ada yang tidak kena dengannya! ! !
曾经蜡笔没有小新2017-05-16 16:56:49
di mana Pengecualian Ralat,
di mana Pengecualian Ralat,
di mana Pengecualian Ralat.