嗨,伙计们,在一个数据采集器中插入值有问题,返回null,这是我的ajax代码
<script type="text/javascript">
// add a new post
$(document).on('click', '.add-modal', function() {
$('.modal-title').text('Add');
$('#addModal').modal('show');
});
$('.modal-footer').on('click', '.add', function() {
$.ajax({
type: 'POST',
url: 'posts',
data: {
'_token': $('input[name=_token]').val(),
'title': $('#title_add').val(),
'content': $('#content_add').val(),
'date':$('#fecha').val(),
'date2':$('#fecha').val()
}<script/>还有我的商店管理员
public function store(Request $request)
{
$validator = Validator::make(Input::all(), $this->rules);
if ($validator->fails()) {
return Response::json(array('errors' => $validator->getMessageBag()->toArray()));
} else {
$post = new Post();
$post->title = $request->title;
$post->content = $request->content;
$post->fechai = Carbon::createFromFormat('Y-m-d', $request->fecha);
$post->fechaf = $request->datepicker1;
$post->user_id = \Auth::user()->id;
$post->save();
return response()->json($post);
}
}为什么两个数据采集器返回null
视图
<div class="form-group" >
<label class="control-label col-sm-2" for="date2">Fecha 2:</label>
<div class="input-group">
<input type="text" class="form-control" id="datepicker1" name="fecha1">
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
</div>这是我的数据采集器,我瘦了我的ajax,没有工作的好
发布于 2017-05-15 04:52:07
您使用date作为$_POST密钥,而不是fecha
$post->fechai = Carbon::createFromFormat('Y-m-d', $request->date);你的身份证不正确
'date':$('#datepicker1').val(),
https://stackoverflow.com/questions/43971748
复制相似问题