阿贾克斯在Magento不工作工作、阿贾克斯、Magento

2023-09-10 18:29:25 作者:心扑通扑通乱跳

我只是初学者的Magento。我想从我的.phtml作为运行在Magento的AJAX file.I阅读博客 FOT,但没有得到任何success.I只是想发送邮件到我的客户,当过一个表单提交的产品页面。

I am just beginner of Magento. I want to run an ajax in Magento from my .phtml file.I read a blog fot it but did not get any success.I just want to send a mail to my client when ever a form is submitted on Product Page.

这是我的.phmtl文件的路径和code。

This is my .phmtl file path and code.

 path - web/frontierFinal/app/design/frontend/default/frontier/template/catalog/product/view.phtml

和code

jQuery.ajax({
                        url: "<?php echo 

    $this->getUrl('groupedajax/ajax/index') ?>",
                            type: "POST",
                            data: "size=434",
                            success: function(data) {
                            $j('#thankyou').html(data);
                            }
                        });

我只是遵循了上述博客的步骤

I just followed the steps of the above mentioned blog as

1)首先,我创建一个名为模块groupedajax / WEB / frontierFinal / groupedajax

1) First I create a module named groupedajax /web/frontierFinal/groupedajax

,然后一个新的目录控制器和PHP文件 /web/frontierFinal/groupedajax/controllers/AjaxController.php

and then a new directory controllers and .php file /web/frontierFinal/groupedajax/controllers/AjaxController.php

然后$ C $ AjaxController.php了C

then code of AjaxController.php

<?php
class Creare_Groupedajax_AjaxController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        echo "sasd";
    }
}
?>

再配置命名为 /httpdocs/web/frontierFinal/groupedajax/etc/config.xml

和$ C $这个文件c为

and code of this file is

<?xml version="1.0"?>
<config>
  <modules>
    <Creare_Groupedajax>
      <version>0.1.0</version>
    </Creare_Groupedajax>
  </modules>
  <frontend>
    <routers>
      <groupedajax>
        <use>standard</use>
        <args>
          <module>Creare_Groupedajax</module>
          <frontName>groupedajax</frontName>
        </args>
      </groupedajax>
    </routers>
    <layout>
      <updates>
        <groupedajax>
          <file>groupedajax.xml</file>
        </groupedajax>
      </updates>
    </layout>
  </frontend>
</config>

再映射XML文件/httpdocs/web/frontierFinal/app/design/frontend/default/frontier/layout/groupedajax.xml

<?xml version="1.0"?>
<layout version="1.0">
  <groupedajax_ajax_index>
    <block type="groupedajax/groupedajax" name="root" output="toHtml" template="template/catalog/product/view.phtml" />
  </groupedajax_ajax_index>
</layout>

我知道我没有的目录,多数民众赞成清楚的了解为什么这个问题是未来up.But我需要你们的帮助球员。

I know I dont have clear understanding of directories thats why this problem is coming up.But I need your help guys.

当我运行AJAX它显示404未找​​到。

When I run ajax it shows 404 not found.

请帮助谢谢

推荐答案

在您.phtml作为文件中使用

In your .phtml file use

<script type="text/javascript">
  jQuery("#form_post").submit(function() {
    var posdata = jQuery("#form_post").serializeArray();
    var url = "<?php echo Mage::getUrl('test/index/save') ?>";
    jQuery.ajax({
      type: "POST",
      url: url,
      datatype: "text",
      data: posdata,
      success: function(data)
      {
        $$(".result").invoke("update",data.replace(/\"/g, ""));
      }
    });
    return false;
  });
</script>

和控制器中添加

public function saveAction()
{
  $result=Mage::app()->getRequest()->getParam('telephone');;
  $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}