2

I made an ajax request (in the admin html) and got the following response:

"{"error":true,"message":"You entered an invalid Secret Key. Please refresh the page."}"

new Ajax.Request('getAjaxExportUrl() ?>', { method: 'get', parameters: { "store" : "someStore" }

.

public function getAjaxExportUrl() { return $this->getUrl('someURL'); }

What's wrong?

1 Answer 1

17

Magento is using secure key validation in admin aria.

Simplest way to use secure key is use POST and add form_key to data. Example:

jQuery.ajax( {
    url: 'http://mage.dev/admin/vendor/module/validateTest',
    data: {form_key: window.FORM_KEY},
    type: 'POST'
}).done(function(a) { 
    console.log(a); // log: {a: "b"}
});
2

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.