When I pass the results from getJSON to parseInfo() function just like the one below, is it possible to get results back into a php variable so that I could put the latter through another php function.
$.getJSON('getinfo.php', { id:id }, parseInfo);
function parseInfo(data) {
<?php
$some_var = json_decode(data);
function some_function($some_var) {
// rest of the script here...
}
?>
}
Can anyone please help me out with this? I would really appreciate it.
Cheers!
PHP runs BEFORE the page is sent. Javascript runs AFTER the page is sent. Therefore the only way to can run PHP is to request a page.
So, if you wanted to pass data to PHP, you would have to call another page like ajax.php :
<?php
$data = $_POST['data'];
// ... do stuff ...
?>
From your script:
$.post('ajax.php', data);
See this question.
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.