0

嗨,我想将代码输出[json['information']为实际转换的 html 代码。

目前,它似乎只是将整个字符串输出为纯文本(未格式化的 html,因此您可以看到所有标签等)我仍在学习,json所以我不确定应该如何处理收到的内容以使其成为正确的 html .

提前致谢

$('.engineering-services').live('click', function() {     
$.ajax({
    url: 'index.php?route=information/information/homepage_info',
    type: 'post',
    data: {info_for : 'engineering'},
    dataType: 'json',
    success:    function(json){

    $('#engineering-content').html(json['information']);
    },
    error: function(json) {
    alert('fail');
    }
    });
   });

编辑,这是 PHP ...

    public function homepage_info() {
    $this->load->model('catalog/information');
    $json = array();
    if (isset($this->request->post['info_for'])) {
        if ($this->request->post['info_for'] == 'engineering') {    
            $information_info = $this->model_catalog_information->getInformation(10);
            $json['information'] = $information_info['description'];                
            }
            $this->response->setOutput(json_encode($json));
            }

            }
4

2 回答 2

0

您的 HTML 字符串似乎将特殊字符编码为 HTML 实体,例如<to&lt;等。从您展示的 PHP 中,它可能已在数据库中编码(也许您在保存之前进行了编码)。

您应该可以使用以下方法修复它html_entity_decode

$json['information'] = html_entity_decode($information_info['description']);
// or, a few lines later:
// $this->response->setOutput(html_entity_decode(json_encode($json)));
于 2013-04-15T22:05:43.750 回答
0

看起来您正在为您的 php 控制器使用 Open cart。为了发回带有正确 json 标头的响应,Open Cart 方式如下:

$this->load->library('json');
$this->response->setOutput(Json::encode($json));

希望有帮助。

于 2013-04-15T22:24:20.230 回答