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.

asked Jan 30, 2016 at 9:26
3
  • Which magento version are you using? Commented Jan 30, 2016 at 10:10
  • Using magento v1.9 Commented Jan 30, 2016 at 10:11
  • Please tell full version? Commented Jan 30, 2016 at 11:08

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

saravanavelu
3,95123 gold badges38 silver badges52 bronze badges
answered Jan 30, 2016 at 11:13
7
  • @Febian, I have tried what you have suggested above but still my page shows 404 not found page on URL "example.com/index.php/admin/allstock/index/product_id/1829/key/…" Commented Jan 30, 2016 at 11:27
  • Login/Logout, ACL is loaded on login Commented Jan 30, 2016 at 12:00
  • I have cleared out all CACHE and did logout then login but no effect still getting 404 error page. Commented Jan 30, 2016 at 12:12
  • Can you edit your question and add the new config.xml? Commented Jan 30, 2016 at 12:15
  • yes I have edited my config.xml, please check Commented Jan 30, 2016 at 12:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.