0

I am calling admin controller via ajax, but it is not being called. Here is the controller file-

Assel/Allstock/controllers/Adminhtml/AllstockController

<?php 
class Assel_Allstock_Adminhtml_AllstockController extends Mage_Adminhtml_Controller_Action
{
  protected function _isAllowed()
  {
    return true;
  } 

  protected function _initAction() {
        $this->loadLayout()
            ->_setActiveMenu('Purchase')
            ->_addBreadcrumb(Mage::helper('adminhtml')->__('Allstock'), Mage::helper('adminhtml')->__('Allstock'));

        return $this;
  }

  public function indexAction() {
        $this->_initAction()
             ->_addContent($this->getLayout()->createBlock('allstock/adminhtml_allstock'))
            ->renderLayout();
  }

  public function productStockAction()
  {
      return "hello";
  }

  // Used for AJAX loading
   public function gridAction()
   {
        $this->loadLayout();
        $this->getResponse()->setBody(
            $this->getLayout()->createBlock('allstock/adminhtml_allstock_grid')->toHtml()
        );
   }
}
?>

Here is my config.xml-

 <?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
        <Assel_Allstock>
            <version>1.0.0</version>
        </Assel_Allstock>
   </modules>
   <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <assel_allstock after="Mage_Adminhtml">Assel_Allstock_Adminhtml</assel_allstock>
                    </modules>
                </args>
           </adminhtml>
        </routers>
    </admin>
   <global>
      <helpers>
            <allstock>
                <class>Assel_Allstock_Helper</class>
            </allstock>
        </helpers>
        <blocks>
            <allstock>
                <class>Assel_Allstock_Block</class>
            </allstock> 
        </blocks>
   </global>
    <adminhtml>
        <layout>
            <updates>
                <assel_allstock>
                    <file>assel/allstock.xml</file>
                </allstock>
            </updates>
        </layout>
    </adminhtml>
</config>

Here is the template file --

adminhtml/base/default/template/assel/allstock.phtml

 <script>
        var url= "<?php echo $this->getUrl('allstock/adminhtml_allstock/productStock/'); ?>";
        $j('#product_search').keyup(function() {
          delay(function(){
            new Ajax.Request(url, {
                  method: 'get',
                  onSuccess: function(response){debugger 
                  },
                  onFailure:  function(response) {debugger
                    Element.hide('loading-mask'); 
                    alert("An error has been occured during Ajax call, please try again");
                  },
            });
          }, 2000 );
        });
        var delay = (function(){
          var timer = 0;
          return function(callback, ms){
          clearTimeout (timer);
          timer = setTimeout(callback, ms);
         };
        })();
    </script>

I am getting this value in url variable in ajax-

"http://example.com/index.php/admin/allstock/productStock/key/NuEkv9QcEXoP4NWr/?isAjax=true"

I am getting 404 error in ajax call. Not sure why I am getting this. Can anyone help me into this.

3

1 Answer 1

0

Starting with MAgento 1.9.2.2 you are no longer allowed to implement your own admin routes, but instead have to use and extend the used Controller list, like this:

app/code/community/Pulsestorm/Adminhello/etc/config.xml

<config>
    <!-- ... -->
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Pulsestorm_Adminhello after="Mage_Adminhtml">Pulsestorm_Adminhello</Pulsestorm_Adminhello>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <!-- ... -->
</config>

Source: Alan Storm

7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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