尝试提交我的Laravel表单而不刷新页面 [英] Trying to submit my laravel form without the page refreshing
本文介绍了尝试提交我的Laravel表单而不刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试提交表单,而无需刷新页面.我没有成功,但在控制台日志中不断收到错误消息,提示服务员说页面有错误.我不知道我在做什么错.有谁可以帮助我吗?我正在使用laravel,ajax.这是我的代码.预先感谢
I am trying to submit my form without having to refresh the page. I haven't been successful I keep getting error message in the console log that the serever is saying the page is wrong.I don't know what I'm doing wrong. Can someone help me please? I am using laravel,ajax. Here is my code. Thanks in advance
//Ajax
$('.formform' ).submit(
function( e ) {
$.ajax( {
url: '{{ url('profileupdate') }}',
type: 'POST',
data: new FormData( this ),
processData: false,
contentType: false,
success: function(result){
console.log(result);
}
} );
e.preventDefault();
}
);
//The form
{!!Form::open(['url'=>['profileupdate',Auth::user()->id],'method'=>'POST','files'=>true,'class'=>'formform formform2','enctype' => 'multipart/form-data']) !!}
<div style="position:relative; left:.5em; font-size:1.3em;">
ADD YOUR VIDEO!<br>
</div>
<br>
{{Form::file('video',array('id'=>'file','class'=>'thefile'))}}
<label for="file" class="btn btn-default" style="background:none;">Choose a file</label> <span class="tt"></span>
{{Form::text('Company','',array('placeholder'=>'Company Name','class'=>'form-control'))}}
{{Form::text('city','',array('placeholder'=>'City and State','class'=>'form-control', 'size'=>'35px','height'=>'15px','id'=>'location-input','autocomplete'=>'off'))}}
{{Form::text('zip_code','',array('placeholder'=>'Zip Code','class'=>'form-control'))}}
{{Form::text('Phone_Number','',array('placeholder'=>'Phone Number','class'=>'form-control'))}}
{{Form::submit('Submit', array('class'=>'btn btn-warning form-control','id'=>'submitty profile1_submit','style'=>'border:none; margin-top:3%; margin-bottom:5%;', 'data-toggle'=>"modal", 'data-target'=>"#profile_modal"))}}
{!!Form::close() !!}
//Here is the route
Route::post('profileupdate/{id}','Profile1Controller@update');
推荐答案
您错过了参数id
'profileupdate/{id}'
更改此:
You miss the parameter id
'profileupdate/{id}'
Change this :
url: '{{ url('profileupdate') }}',
使用
url: {!! route('profileupdate', ['id' => Auth::user()->id ]) !!}
别忘了在数据中添加csrf的令牌(JavaScript部分)
and don't forget to add the token for csrf in data (javascript part)
"_token": $('#token').val()
这篇关于尝试提交我的Laravel表单而不刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文