我想提交圖像上傳使用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這應該是代碼。 –