Magento Ajax-如何仅获取身体部位?
我正在尝试对Magento使用ajax调用。当我通过Ajax调用一个块页面时,我得到了所有的HTML,包括head、css、javascript和body。如何仅获取身体部位?如果您能提供有关您调用的“块页”的更多信息,则可能更容易识别问题。默认情况下,Magento包含所有页面的Magento Ajax-如何仅获取身体部位?,ajax,magento,Ajax,Magento,我正在尝试对Magento使用ajax调用。当我通过Ajax调用一个块页面时,我得到了所有的HTML,包括head、css、javascript和body。如何仅获取身体部位?如果您能提供有关您调用的“块页”的更多信息,则可能更容易识别问题。默认情况下,Magento包含所有页面的布局标记,即使在AJAX调用中,它也会为您提供页眉和页脚 要发送一个页面而不需要所有额外的内容,您有几个选项。首先,您可以自己手动设置输出,完全避免布局系统。Magento为单页签出功能执行此操作: $result =
布局标记,即使在AJAX调用中,它也会为您提供页眉和页脚
要发送一个页面而不需要所有额外的内容,您有几个选项。首先,您可以自己手动设置输出,完全避免布局系统。Magento为单页签出功能执行此操作:
$result = array( 'foo' => 'foo', 'bar' => 'bar', );
$this->getResponse()->setBody(Zend_Json::encode($result));
您还可以修改此方法以使用如下自定义布局处理程序:
protected function loadPage() {
$layout = $this->getLayout();
$update = $layout->getUpdate();
$update->load('your_custom_handle');
$layout->generateXml();
$layout->generateBlocks();
$output = $layout->getOutput();
$result = array( 'outputHtml' => $output, 'otherVar' => 'foo', );
$this->getResponse()->setBody(Zend_Json::encode($result));
}
在布局文件中:
<your_custom_handle>
<remove name="right"/>
<remove name="left"/>
<block type="module/block" name="root" output="toHtml" template="module/template.phtml"/>
</your_custom_handle>
默认情况下,此布局在main.xml
布局文件中定义,并呈现popup.phtml
模板,可能适合您使用
如果你仍然有困难,让我知道,我们可以尝试其他事情。希望有帮助
谢谢,
乔谢谢你。为我节省了大量时间。请注意,如果复制和粘贴布局文件示例,请确保将
type=“module/block”
更改为实际的magento块类型,如type=“page/html”
,或为您的模块定义的自定义块类型。精彩、简单、高效。。。我喜欢它。感谢JoeJust想要在布局文件中表达output=“toHtml”的重要性。这是实际导致布局生成html的代码。如果没有,您将无法获得任何html。还有第三种方法
$this->loadLayout('popup');