我在laravel 5.1中使用ajax来获取sotre数据 我有像这样的控制器
public function store(Request $request)
{
$validator = Validator::make($request->input(), [
'username' => 'required',
'password' => 'required',
]);
if ($validator->fails()) {
return view('common.adminwizard.technicianajax')->withErrors($validator)->withInput();
}
}
当我使用withInput()方法时ajax响应
Internal Server Error
但是当我删除这个方法时,ajax工作正常
而不是传递数据
ajax脚本
$(document).on("click", "#test-submit-btn", function() {
$.ajax({
type:'POST',
url:'/test',
data:$("#test_form").serialize(),
success: function(result){
$('#test_ajax_div').html(result);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
})
答案 0 :(得分:0)
我用这段代码解决了
public function store(Request $request)
{
$validator = Validator::make($request->input(), [
'username' => 'required',
'password' => 'required',
]);
if ($validator->fails()) {
return view('common.adminwizard.technicianajax')->withErrors($validator)->with(['request'=>$request]);
}
}