Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento adminhtml AJAX query returns 302 status
    primarykey
    data
    text
    <p>I am currently developing a Magento extension whose main components are a frontend widget and a backend admin options panel. I have no frontend controller, but I have an <code>adminhtml</code> controller that is giving me some trouble. Here is some of the code in my controller.</p> <p>File: /app/code/community/Mynamespace/Myextension/controllers/Adminhtml/MybackendController.php</p> <pre><code>class Mynamespace_Myextension_Adminhtml_MybackendController extends Mage_adminhtml_Controller_Action { protected function normalAction() { } protected function ajaxAction() { die('got here'); } } </code></pre> <p><code>normalAction</code> is an action that is called by navigating through links such as <code>http://mystore.com/index.php/admin/mybackend/normal/key/.../</code> . There are a few actions like this such as <code>index</code>, <code>save</code>, <code>edit</code>, <code>grid</code>, etc. The entry point to my controller is a menu entry that leads to the <code>index</code> action. All such actions work as expected.</p> <p><code>ajaxAction</code> is an action that is called only through an AJAX POST query.</p> <p><em>The problem is that whenever I attempt to do this, I get a 302 HTTP status code reply that redirects to the admin dashboard</em> (<code>admin/index/index</code>). If I try to access this action directly by typing its link in the browser, I still get a 302. If I add a menu entry to this action, then it works as expected and I see the "got here" text.</p> <p>The Javascript/jQuery code that does the AJAX request is not complex:</p> <pre><code>$.post( 'http://mystore.com/index.php/admin/mybackend/ajax/key/.../', somePostDataObject, function() { alert( 'success' ); } ); </code></pre> <p>Note that the success function gets called even though the status code is 302.</p> <p>I tried debugging the routing mechanism to understand exactly what causes it to redirect. So far I have deduced that a problem occurs in the <code>preDispatch</code> method of the <code>Mage_Core_Controller_Varien_Action</code> class. The module, controller and action are successfully resolved and the request is marked as dispatched (<code>_dispatched</code> property is true) until the <code>controller_action_predispatch</code> event is dispatched. After the event is resolved, the request appears as not being dispatched (<code>_dispatched</code> becomes false). Presumably one of the objects that listen for this event does some further processing on the request and rejects it. I have not been able to debug any deeper than this.</p> <p>Normally I would post some code to help you understand what's going on even better, but there are quite a lot of lines to copy from the various configuration files and classes, so I will do that as people write comments or answers asking to see specific files. So far, I believe the configuration is correct, as all the other functionality besides the AJAX request is working ok.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload