1

I follow this tutorial to use Ajax request in my button: http://www.atwix.com/magento/add-button-to-system-configuration/

But clicking on the button I get the error "Not Found 404" to url:

http://127.0.0.1:8080/316store/index.php/admin/adminhtml_mateusvitali_sigepweb_options/check/key/ab6b3729a1d318e6d7bd970c5b8d333e/?isAjax=true&&...

My button.phtml

location: /app/design/adminhtml/default/default/template/mateusvitali/system/config/button.phtml

<script type="text/javascript">
    //<![CDATA[
    function check() {
        new Ajax.Request('<?php echo $this->getAjaxCheckUrl() ?>', {
            method:     'get',
            onSuccess: function(transport) {
               alert('Sent notification.');
            },
            onFailure: function(transport) {
               alert("Couldn't send a notification.");
            }
        });
    }
    //]]>
</script>

<?php echo $this->getButtonHtml() ?>

My Button.php

location: /app/code/local/MateusVitali/SigepWeb/Block/Adminhtml/System/Config/Form/Button.php

class MateusVitali_SigepWeb_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
{
    /*
     * Set template
     */ 
    protected function _construct()
    {
        parent::_construct();
        $this->setTemplate('mateusvitali/system/config/button.phtml');
    }

    /**
     * Return element html
     *
     * @param  Varien_Data_Form_Element_Abstract $element
     * @return string
     */
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
    {
        return $this->_toHtml();
    }

    /**
     * Return ajax url for button
     *
     * @return string
     */
    public function getAjaxCheckUrl()
    {
        return Mage::helper('adminhtml')->getUrl('adminhtml/adminhtml_mateusvitali/check');
    }

    /**
     * Generate button html
     *
     * @return string
     */
    public function getButtonHtml()
    {
        $button = $this
            ->getLayout()
            ->createBlock('adminhtml/widget_button')
            ->setData(
                array(
                    'type'      => 'button',
                    'id'        => 'mateusvitali_update',
                    'label'     => $this->helper('adminhtml')->__('Check'),
                    'onclick'   => 'javascript:check(); return false;'
            )
        );

        return $button->toHtml();
    }
}

My MateusVitaliController.php

location: /app/code/local/MateusVitali/SigepWeb/controllers/Adminhtml/MateusVitaliController.php

class MateusVitali_SigepWeb_Adminhtml_MateusVitaliController extends Mage_Adminhtml_Controller_Action
{
    /**
     * Return some checking result
     *
     * @return void
     */
    public function checkAction()
    {
        $successCode = 1;
        Mage::app()->getResponse()->setBody($successCode);
    }
}
  • It's hard to tell without knowing your folder structure and how you defined your controllers. But I believe the Ajax URL in getAjaxCheckUrl method could be wrong. Please update your question. – Anna Völkl Jan 2 '16 at 17:50
  • @AnnaVölkl I also think getAjaxCheckUrl is wrong. I edited and placed location – Mateus Vitali Jan 2 '16 at 19:39
  • 1
    Also, if you do not have the permissions set, the URL will not be allowed. You should have something in adminhtml.xml. If you do, make sure you log out of the admin, then log back in. Your permissions are set when you log in, so if you have not logged out and back in, you are not able to access that new controller. – RussellAlbin Jan 3 '16 at 17:39
1

I think it is related to your config.xml. Try putting this on your config.xml:

<admin>
 <routers>
  <adminhtml>
   <args>
    <modules>
     <matheusvitali_sigepweb after="Mage_Adminhtml">MatheusVitali_SigepWeb_Adminhtml</matheusvitali_sigepweb>
    </modules>
  </args>
 </adminhtml>

and change your block method to this:

public function getAjaxCheckUrl(){
  return Mage::helper('adminhtml')->getUrl('adminhtml/mateusvitali/check');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.