I have this part of javascript, How do I return res.success and res.reload from php?
if (res.success) {
NioApp.Toast(res.success, 'success');
if (res.reload) {
setTimeout(function() {
location.reload();
}, 900);
}
}
I tried $return [‘res’ => ‘success’] but didn’t work for me.
2
Answers
The question is not that clear, But I am just trying to solve it. If you want to get the value from PHP to js, then either you need to use an async API call to the server to get the value. or you need to echo out the value to some HTML hidden elements and use javascript to get the value to a variable using getElement.But if you want to send the value to the server then use the get or post method.
I guess by ‘res’ you meant ajax response here, if so, you need to echo out JSON from PHP file.
PHP
Script