在我看来,我们称之为 View-A,我在提示符中从用户那里得到一个输入并将其分配给一个变量,然后我需要在浏览器中加载另一个视图,比如视图 B,同时传递该变量。
说,在我的 中viewA.blade.php
,我接受了用户的输入并将其分配给 variable usersInput
。现在我需要将它发送到视图 B,它在 web.php 中的路由定义在Route::get('editRecord', 'MyController@displayEditRecordView')->name('editRecordFormView');
.
问题是如何从我的刀片视图中编写的 javascripteditRecordFormView
在浏览器中加载 route() 并将变量传递给它?usersInput
@Tushar在我的 ViewA.blade.php 中:
$.ajax({
url: url_editRecordView.url,
data: {
usersInput: dataToSend.usersInput,
},
method: "get",
cache: false,
success: function (dataReturned, stringStatus, jqXHR) {
console.log("dataReturned from mYController.displayEditRecordFormView:-");
console.log(dataReturned);//check
console.log("Type of dataReturned:-" + typeof dataReturned); //SAME DATA COMES BACK, AS THE DATA I SENT
},
error: function (jqXHR, stringStatus, stringExceptionThrown) {
alert("Error! status: " + stringStatus + " ExceptionThrown: " + stringExceptionThrown);//check
}
});
在我的 MyController 中:
public function displayEditRecordFormView (Request $request) {
error_log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");//check
error_log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");//check
$title= $request->input('usersInput');
error_log("In displayEditRecordFormView: title: ".$title);//check
$allPaintingsArray = $this->getAllPaintingsArraySanitized();
$data = [
"allPaintingsArray"=>$allPaintingsArray ,
"title"=>$title
];
return view("paintings.editRecordForm")->with("allGoodData", $data);
}