使用智能模板传递其他数据

时间:2011-04-16 06:12:47

标签: php smarty

我的应用程序使用大量的ajax请求来获取数据。我在服务器端使用smarty模板。我目前正在做的是检测请求是否是服务器端的AJAX请求,并使用smarty模板返回相应的html。但是现在我想要以JSON格式传递更多数据和html。所以我的JSON格式看起来像这样

{"body" : "MY HTML", "data1" : "value1", "data2" : "value2"} 

Smarty可以这样做吗?

1 个答案:

答案 0 :(得分:0)

你可以使用这种风格用json在数组中发送多个值

注意:以下只是逻辑,使其与您的smarty

兼容
$return_data= array ('body'=>"MY HTML", 'data1'=>"value1", 'data2'=>"value2")
echo json_encode($return_data); 
//and retrieve on php side (with smarty logic)
$get_json=json_decode($return_data,TRUE);
$get_json['body'];
$get_json['data1'];
$get_json['data2']

Reference