将json值解码为php变量

编程入门 行业动态 更新时间:2024-10-25 10:28:22
本文介绍了将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变量

本文发布于:2023-08-03 08:09:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1285500.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   json   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!