开发者

Pass other data with smarty template

My application uses a lot of ajax requests to get the data. I am using smarty 开发者_开发问答template on the server side. What I am current doing is detecting if the requesting is AJAX request on the server side and return corresponding html using smarty templates. But now I want to also pass some more data along with html in JSON format. So my JSON format would look like this

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

Is it possible to do so with Smarty?


u can send multiple value in array with json using this style

Note: below is only logic, make it compatible with yoursmarty

$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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜