Frage

I'm inside the Admin area, I'm adding a check inside the products, inside my File phtml write:

<?php $ajaxUrl = Mage::helper('adminhtml')->getUrl('adminhtml/MyCompany_MyModule_AjaxController/check'); ?>

This is real path

\http\app\code\local\MyCompany\MyModule\controllers\ajaxController.php

This is the Function inside file phtml

function check(element) {
    new Ajax.Request('<?php echo $ajaxUrl ; ?>', {
    method:     'get',
    onSuccess: function(transport) {
        alert('Sent notification.');
    },
    onFailure: function(transport) {
        alert("Couldn't send a notification. ");
        console.log(transport);
    }
});}

This is inside my controller:

    public function checkAction()
{
    $value= 'example';
    Mage::app()->getResponse()->setBody($value);
}

and this is my config.xml

    <admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <MyCompany_MyModule before="Mage_Adminhtml">MyCompany_MyModule</MyCompany_MyModule>
                    <MyCompany_MyModule after="Mage_Adminhtml">MyCompany_MyModule_Adminhtml</MyCompany_MyModule>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Premise, the ajax call works but I always get 404 error back I'm pretty sure the paths are wrong, but I can not understand how to set them up, can you help me? thank you

War es hilfreich?

Lösung

Try this

<admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <MyCompany_MyModule before="Mage_Adminhtml">MyCompany_MyModule_Adminhtml</MyCompany_MyModule>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

And controller file should be at: http/app/code/local/MyCompany/MyModule/controllers/Adminhtml/AjaxController.php

<?php

class MyCompany_MyModule_Adminhtml_AjaxController extends Mage_Adminhtml_Controller_Action
{
    public function checkAction()
    {
        $value= 'example'; Mage::app()->getResponse()->setBody($value);

    }
    protected function _isAllowed() {
        return true;
    }
}

You need to put this code for URL. <?php $ajaxUrl = Mage::helper('adminhtml')->getUrl('adminhtml/ajax/check'); ?>

Andere Tipps

Path http\app\code\local\MyCompany\MyModule\controllers\Adminhtml\AjaxController.php

<?php 
class MyCompany_MyModule_Adminhtml_AjaxController extends Mage_Adminhtml_Controller_Action {
public function checkAction()
{
    $successCode = 1;
    Mage::app()->getResponse()->setBody($successCode);
} 
}

Config.xml

            <adminhtml>
            <args>
                <modules>
                    <MyCompany_MyModule before="Mage_Adminhtml">MyCompany_MyModule_Adminhtml</MyCompany_MyModules>
                </modules>
            </args>
        </adminhtml>

Ajax Call

<?php $ajaxUrl = Mage::helper('adminhtml')->getUrl('adminhtml/MyCompany_MyModule_AjaxController/check'); ?>

function check(element) {

new Ajax.Request('<?php echo $ajaxUrl; ?>', {
    method:     'get',
    onSuccess: function(transport) {
        alert('Sent notification.');
    },
    onFailure: function(transport) {
        alert("Couldn't send a notification. ");
        console.log(transport);
    }
}); }

URL Generated

https://localhost/index.php/admin/MyCompany_MyModule_AjaxController/check/key/b800cc33b4822a6b866056ef0094cee4/?isAjax=true&&form_key=emruvSXuKs9r7Bic

Status Code 404

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top