1

私は次のjquery ajaxを持っています

fnc = {
    ajax : function (){
        $.ajax({
        url: 'index.php?route=module/rows/filterView',
        type: 'get',
        success: function(data) {
            alert(data);
        }
    });
    }
}

これは私のイベント登録です

$(document).on('click','.loadfilter', function() {
    fnc.ajax();
})

そして、これが私のコントローラーです

public function filterView() {
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/collections.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/collections.tpl';
        } else {
            $this->template = 'default/template/module/collections.tpl';
        }

        $this->render();
}

私の collections.tpl には、テスト コンテンツがあります。

しかし、リンクをクリックすると、空のアラートが表示されます。値は含まれていません。

空のアラートが表示される理由。私がここでやっている間違いは何ですか。誰でも助けることができますか

4

1 に答える 1

1

間違いは本当に簡単です:

テンプレートを取得してレンダリングするだけ$this->render();で、出力はまったく行われません。レンダリングされたテンプレートを出力するには、これを呼び出す必要があります:

$this->response->setOutput($this->render());

JSONが出力されることを期待している場合は、単に呼び出します

$this->response->setOutput(json_encode($this->render()));

これは、任意のOpenCart コントローラーを開いて、出力とレンダリングがどのように行われるかを確認するだけで把握できます...

于 2013-11-11T12:09:16.213 に答える