decoding json value into a php variable
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 throug开发者_StackOverflow社区h 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.
精彩评论