我创建了一个自定义前端模块,该模块允许用户通过向导类似过程。我想做这个Ajax。

我正在加载我的布局块。

<batch_index_index>
    <reference name="content">
        <block type="batch/batch" name="batch" template="batch/batch.phtml"/>
    </reference>
</batch_index_index>

但是,使用该PHTML文件返回默认模板,如何使Magento仅返回PHTML文件的内容?

有帮助吗?

解决方案

尝试这个:

<batch_index_index>
    <block type="batch/batch" name="root" template="batch/batch.phtml"/>
</batch_index_index>

其他提示

这是一个模块 github 这有助于开发人员与Ajax一起工作。它也可以在 Magento Connect.

替代方法是,您在控制器中生成块:

$block = $this->getLayout()->createBlock($name);
$this->getResponse()->setBody(json_encode($block->toHtml()));

编辑 按照@sparcksoft的建议添加JSON_ENCODE

许可以下: CC-BY-SA归因
scroll top