0

This is my prototype code:

new Ajax.Request(BASE_URL + 'hospitals', {
        method: 'post',
        postBody:'store_id='+store_id+'&isAjax=1',
        onSuccess: successFunc,
        onFailure:  failureFunc
    });

This is my controller:

class Mynamespace_Mymodul_Adminhtml_HospitalsController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
      var_dump($this->getRequest()->getPost('store_id')); exit();
    }
}

The url it set correct. The post parameters are correct and they are sent. But i the response is this:

{"error":true,"message":"Invalid Form Key. Please refresh the page."} 

What should I do ?

0

All admin URLs should have a key that is generated based on the action controller and action name and some random session key.
You cannot simply do a call to ROOT/hospitals/.
You need something like this ROOT/module/controller/action/key/{some hash key here}/?other=params.

I assume you are making the ajax call from a template file.
You should do the call like this:

<?php $url = $this->getUrl('hospitals');?><!-- this will generate the proper url-->
<script type="text/javascript">
    new Ajax.Request('<?php echo $url?>', {
        method: 'post',
        postBody:'store_id='+store_id+'&isAjax=1',
        onSuccess: successFunc,
        onFailure:  failureFunc
    });
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.