【发布时间】:2016-05-13 16:50:19
【问题描述】:
您好,我是 magento 的新手,我正在尝试从前端通过 jquery ajax 调用简单的自定义 php。我在谷歌搜索他们给出了创建自定义模块的答案,然后你可以通过 jquery ajax 调用 php。我已尝试以下步骤是我尝试过的以下步骤请检查并告诉我我的错误是什么
<script>
var jq = jQuery.noConflict();
jq(document).ready(function(){
jq(".listing_duplicate" ).on( "click", function() {
var id= this.id;
var uniqu_number = id.split("_");
var unique = uniqu_number[3];
jq.ajax({
type: "POST",
dataType: "JSON",
data :{'value':unique},
url :"<?php echo $this->getUrl('customajax/ajax/index'); ?>",
success:function(data){
alert(data);
}
});
});
});
</script>
上面是我调用ajax的phtml文件
我在下面的路径中创建了自定义模块
我创建了xxx.com\app\code\local\Custom\Customajax\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<ThomasRyan_Checkoutajax>
<version>0.1.0</version>
</ThomasRyan_Checkoutajax>
</modules>
<frontend>
<routers>
<customajax>
<use>standard</use>
<args>
<module>Custom_Customajax</module>
<frontName>customajax</frontName>
</args>
</customajax>
</routers>
<layout>
<updates>
<checkoutajax>
<file>checkoutajax.xml</file>
</checkoutajax>
</updates>
</layout>
</frontend>
</config>
在这条路径中我创建了控制器xxx.com\app\code\local\Custom\Customajax\controllers\AjaxController.php
<?php
class ThomasRyan_Checkoutajax_AjaxController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
echo 'Hello Index!';
}
}
在这条路径中我创建了块xxx.com\app\code\local\Custom\Customajax\block\Customajax.php
<?php
class Custom_Customajax_Block_Customajax extends Mage_Core_Block_Template
{
echo "teswtme";
}
?>
最后激活我添加的模块xxx.com\app\etc\config.xml
<blocks>
<custom_customajax>
<class>Custom_Customajax_Block</class>
</custom_customajax>
</blocks>
xxx.com\app\etc\modules\ThomasRyan_Checkoutajax.xml
<?xml version="1.0"?>
<config>
<modules>
<ThomasRyan_Checkoutajax>
<active>true</active>
<codePool>local</codePool>
</ThomasRyan_Checkoutajax>
</modules>
</config>
请告诉我在为我调用 jquery ajax 时出错的地方,它显示此错误未找到为什么它显示以下错误是我的错误。
POST http://localhost/xxx.com/index.php/customajax/ajax/index/ 404 (Not找到)
【问题讨论】:
标签: jquery ajax magento-1.8