try to pass json_encode variable in php to javascript. get an uncaught error in javascript. It works before, not changing anything, and now it doesnt work?!?
JSON variable is fine from PHP. Try to print_r in php, OK. Browser networks also OK.
variables I want to pass in PHP:
$response['id'] = $id;
$response['name'] = $name;
$response['note'] = $note;
$response['image'] = $image;
$response['bumbu'] = $bumbu;
$response['banyak'] = $banyak;
$response['masak'] = $masak;
$response['images'] = $images;
print_r($response);
json_encode($response);
my javascript:
$('#viewResep')
.on('show.bs.modal', function (e) {
var id = $(e.relatedTarget)
.data('id');
console.log('Requested : ' + id);
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// document.getElementById("demo").innerHTML = this.getAllResponseHeaders();
}
};
xhttp.open('GET', 'process_post.php?view=' + id, true);
xhttp.send();
fetch('process_post.php?view=' + id)
.then(text => JSON.parse(text))
.then((data) => {
r_Name = data.name;
r_Note = data.note;
r_Image = data.image;
r_Bumbu = data.bumbu;
r_Banyak = data.banyak;
r_Masak = data.masak;
r_Images = data.images;
});
});
I want to get all variables passed using json_encode in my javascript