我基本上需要在刀片视图中单击一个按钮来触发js文件中的函数,然后将一些值发送到控制器并返回视图。使用下面的代码,是否需要为此创建路由?谢谢
view:
<div id="sendAsEmailTest">SEND AS EMAIL TEST</div>
js:
$('#sendAsEmailTest').on('click', function () {
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "FormController/TestFunction",
data: { name: "John" }
}).done(function( msg ) {
// alert( "Data Saved: " + msg.name );
});
});
FormController:
public function TestFunction(Request $request)
{
return view('calculator.calculator',
[
'testdata' => $request,
]
);
}
你的路线应该张贴
route::post('formController/testfunction'@'FormController@TestFunction')
只是
public function TestFunction(Request $request)
{
dd($request->name)<---- you get your attribute value here
}
then correct
js:
$('#sendAsEmailTest').on('click', function () {
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: "POST",
url: "formController/testfunction",<------------------all letters in small
data: { name: "John" }
}).done(function( msg ) {
// alert( "Data Saved: " + msg.name );
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句