我的控制员:
public function store(Request $request)
{
if($request->ajax()){
return response()->json([
"pesan" => $request->all()
]);
}
}
我的modalScript.js
$("#createLoker").click(function(){
var datas = $("#judul","#namaPt","#deadline","#deskripsi","#profilePt").val();
var route = "http://localhost:8000/lowongan";
var token = $("#token").val();
$.ajax({
url:route,
headers : {'X-CSRF-TOKEN':token},
type: 'POST',
dataType: 'json',
data:{judul:datas,
namaPt:datas,
deadline:datas,
deskripsi:datas,
profilePt:datas
}
});
});
这是我的index.blade
{!!Form::open()!!}
<input type="hidden" name="_token" value="{{ csrf_token() }}" id="token">
<form class="form-horizontal">
{!!Form::text('judul',null,['id'=>'judul','class'=>'form-control','placeholder'=>'Judul Lowongan'])!!} </div>
{!!Form::text('namaPt',null,['id'=>'namaPt','class'=>'form-control','placeholder'=>'Nama PT'])!!}
..........
{!!Form::close()!!}
{!!Html::script('js/scriptModal.js')!!}
答案 0 :(得分:0)
var datas = $("#judul","#namaPt","#deadline","#deskripsi","#profilePt").val();
将返回undefined,因为jquery无法处理它。
var route = "http://localhost:8000/lowongan";
var token = $("#token").val();
$.ajax({
url:route,
headers : {'X-CSRF-TOKEN':token},
type: 'POST',
dataType: 'json',
data:{judul: $("#judul").val(),
namaPt: $("#namaPt").val(),
deadline: $("#deadline").val(),
deskripsi: $("#deskripsi").val(),
profilePt: $("#profilePt").val();
}
});
当您的所有数据都在表单中时,您可以使用
$('form').serializeArray();
将返回包含所有输入的数组。