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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// 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(':(');
});