【发布时间】:2011-03-28 05:26:02
【问题描述】:
对不起,如果这是基本的,但我整天都在处理这个问题,并且已经到了可以用 Jquery 和 cakephp 做我需要的一切的地方(不确定 cakephp 在这方面是否重要,或者它是否与任何 PHP 相同),我想从 cakephp 函数返回一个变量到 jquery,我已经阅读了如何做到这一点,就像这里:
cakephp:
$test[ 'mytest'] = $test;
echo json_encode($test);
和 jquery:
$.ajax({
type: 'POST',
url: 'http://localhost/site1/utilities/ajax_component_call_handler',
data: {
component_function: component_function,
param_array: param_array
},
dataType: "json",
success: function(data) {
// how do i get back the JSON variables?
}
});
我只是不知道如何在 jquery 中将一个或多个变量恢复为可用的形式,我只想要这个变量,这样我就可以用它做任何其他事情,我一直在寻找我可以通过搜索找到的东西但它并没有让我完全清楚..感谢您的任何建议。
【问题讨论】:
-
Álvaro G. Vicarios 的答案是正确的 - 但请注意,您使用的 PHP JSON 示例将返回 {"mytest": null} 因为您将空变量 $test 分配给数组 $test
标签: php jquery ajax json cakephp