将json值解码为php变量 [英] decoding json value into a php variable

查看:133
本文介绍了将json值解码为php变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将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变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆