I'm trying to send data received from controller to another page through javascript fetch API. how can I passes this data
$(document).on('click', '#edit-property', function () {
var data = $(this).data('info');
fetch('/property/' + data)
.then(response => {
if (response.ok) {
response.json().then(property => {
console.log(property);
window.location.href = "/property-details";
})
} else {
console.error(' Reponse serveur : ' + response.status);
}
});
});
You can pass the data as params in your url as you redirect to the page you are sending the data to.
response.json().then(property => {
window.location.href = "/property-details?property="+property ;
})
Then here is the controller method retrieving data attached to the url:
MyDataController.php
public function getRequestParams(Request $request)
{
$property = request()->property;
return view('display_property')->with('property', $property));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.