对不起,如果这是基本的,但我一直在处理整天搞清楚这一点,并已经到了我可以用Jquery和cakephp做我需要的一切的地方(不知道cakephp是否重要这或者如果它同任何PHP),我想返回从CakePHP的功能jQuery的一个变量,我读了关于如何做到这一点,就像这里:Jquery,阅读从PHP接收的JSON变量
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中,我只是想变量,所以我可以做任何事情与它,我一直在寻找我可以通过搜索找到,但它没有使我完全清楚..感谢您的任何建议。
ÁlvaroG.Vicarios的答案是正确的 - 但请注意,您使用的PHP JSON示例将返回{“mytest”:null},因为您将空变量$ test分配给数组$ test – becquerel 2010-08-11 07:07:10