Skip to content

Admin Side AJAX Requests

POST

Why am I getting a 302?

If you're trying to make an AJAX post request in the admin and you're getting a 302 you can fix this by using the following:

// Use:
// Mage::helper('adminhtml')->getUrl('adminhtml/.../...', array('_secure' => true))
// to generate your URL.
var url = 'https://www.domain.com/index.php/admin/.../...';

jQuery.ajax({
    method: 'POST',
    url:  url + '?isAjax=true',  // <-- you need to add 'isAjax=true' to your URL
    data: {
        // Your data plus:
        form_key: window.FORM_KEY  // <-- you need to add the current form key to your POST data
    }
}).done(function (json) {
    // Hurray!
    // Now do some stuff.
}).fail(function () {
    console.error(':(');
});