我想提交图像上传使用jQuery的Ajax,但每次我选择一个图像,然后单击提交按钮提醒($(this).serialize())显示 -表单提交与图像上传使用jQuery的ajax在laravel5
_token = TCWpR3n9Uf2FpKMXi639Dcvzhc7t4fVDWDopjZ8V。
这里是我的形式 -
{!! Form::open(['action'=>'[email protected]', 'name'=>'form1', 'id'=>'formId1', 'files'=>true]) !!}
<div class="form-group">
{!! Form::file('image') !!}
</div>
<div class="form-group">
{!! Form::submit('Upload', array('class'=>'btn btn-danger', 'name'=>'image_form_submit' )) !!}
</div>
{!! Form::close() !!}
这里js-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("form").submit(function(e){ //
e.preventDefault();
alert($(this).serialize()); //always alerts the tocken- _token=TCWpR3n9Uf2FpKMXi639Dcvzhc7t4fVDWDopjZ8V
$.ajax({
type:"POST",
url: $(this).attr('action'),
data: $(this).serialize(),
dataType: 'json',
success: function(data){
console.log(data);
},
error: function(data){
}
})
return false;
});
});
</script>
我想通过Ajax获得的形式和岗位的序列化数据到我的控制器。 为什么警报总是显示令牌?
那么,什么数据,你应该得到的形式连载? –
在你的代码中,它们不是表单元素,而是标记。如果你想上传img,那么http://stackoverflow.com/questions/19447435/ajax-upload-image?answertab=active#tab-top这应该是代码。 –