我正在编写一个模块来在Magento中执行一个简单的Ajax调用,但它在控制台中给出了404错误
config.xml文件是
<?xml version="1.0"?>
<config>
<modules>
<Custom_Personalize>
<version>0.1.0</version>
</Custom_Personalize>
</modules>
<frontend>
<routers>
<personalize>
<use>standard</use>
<args>
<module>Custom_Personalize</module>
<frontName>personalize</frontName>
</args>
</personalize>
</routers>
<layout>
<updates>
<personalize>
<file>personalize.xml</file>
</personalize>
</updates>
</layout>
</frontend>
<admin>
<routers>
<personalize>
<use>admin</use>
<args>
<module>Custom_Personalize</module>
<frontName>admin_personalize</frontName>
</args>
</personalize>
</routers>
</admin>
<layout>
<updates>
<personalize>
<file>personalize.xml</file>
</personalize>
</updates>
</layout>
</adminhtml>
</config>
控制器文件是
<?php
class Custom_Personalize_AjaxController extends Mage_Core_Controller_Front_Action
{
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
personalize.xml是
<?xml version="1.0"?>
<layout>
<personalize_ajax_index>
<block type="personalize/personalize" name="root" output="toHtml" template="personalize/ajax.phtml" />
</personalize_ajax_index>
</layout>
在ajax.phtml中
test
和jQuery代码是
<script type="text/javascript">
jQuery(document).on('change', '.shapes', function() {
console.log("hii");
jQuery.ajax({
url: "<?php echo $this->getUrl() ?>"+'personalize/ajax/index',
type: "POST",
data: "size=123456",
success: function(data) {
console.log(data);
return false;
}
});
});
</script>
请建议我缺少什么?
由于
答案 0 :(得分:2)
您已经提到阻止个性化/个性化,您需要在Block / Personalize.php中定义该块,还需要将块定义为 config.xml
如果您没有在扩展程序中定义任何阻止,则可以使用核心/模板:
<?xml version="1.0"?>
<layout>
<personalize_ajax_index>
<block type="core/template" name="root" output="toHtml" template="personalize/ajax.phtml" />
</personalize_ajax_index>
</layout>