当我将getJSON的结果传递给parseInfo()函数时,就像下面的一样,是否有可能将结果返回到php变量中,以便我可以将后者通过另一个php函数.
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在发送页面之前运行.发送页面后运行Javascript.因此,运行PHP的唯一方法是请求页面.
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.
因此,如果您想将数据传递给PHP,则必须调用另一个页面,例如 ajax.php :
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 ... ?>通过您的脚本:
$.post('ajax.php', data);请参见此问题.
更多推荐
将json值解码为php变量
发布评论