1

I have my custom module and everything works fine, but I would like to create separately controller for AJAX actions (AjaxController). Currently I Have only IndexController. Everytime I get:

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

Code snippets are below:

Build URL:

<script type="text/javascript">
    RECALC_SP_URL = "<?=$this->htmlEscape(Mage::helper('adminhtml')->getUrl('*/productcreator_ajax/getSpecialPrice/'));?>";
</script>

**Part of config.xml*:*

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <productcreator after="Mage_Adminhtml">Aiti_ProductCreator_Adminhtml</productcreator>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

AJAX call:

jQuery( "#margin_percent" ).change(function() {
    var $_this = jQuery( this );
    var store_id = 0;
    new Ajax.Request(RECALC_SP_URL, {
        method: 'post',
        parameters: {
            storeId: store_id,
            margin: $_this.val(),
            productId: jQuery('#productcreator_product_id').val(),
        },
        onSuccess: function (transport) {
            var response = JSON.parse(transport.responseText);

            jQuery("#special_price").val(response['special_price']);
        },
        onFailure: function () {

        }
    });
});

Thank you for some help!

0

Below i have add new ajax request url in code. please review it

jQuery( "#margin_percent" ).change(function() {     
    var $_this = jQuery( this );
    var store_id = 0;
    /* margin is controller name. file name is like "marginController.php" & getPercent is function */
    new Ajax.Request('ajaxdata/margin/getPercent/', {
        method: 'get',
        parameters: {
            storeId: store_id,
            margin: $_this.val(),
            productId: jQuery('#productcreator_product_id').val(),
        },
        onSuccess: function (transport) {
            var response = JSON.parse(transport.responseText);

            jQuery("#special_price").val(response['special_price']);
        },
        onFailure: function () {

        }
    });
});
  • My URL is ok, I'm sure - If ajax is sending by get method, all is ok....problem is only with post method. – Sekiphp Jul 23 '18 at 14:39
  • using GET method. I have edit code please review it. – Shorabh Jul 24 '18 at 4:15
  • Is is not possible to use post method? – Sekiphp Jul 25 '18 at 6:20
  • Yes . you to just edit method. Like method: 'post', or method: 'get', – Shorabh Jul 25 '18 at 6:21
  • If I edit method to post, I have problem with form key - {"error":true,"message":"Invalid Form Key. Please refresh the page."} – Sekiphp Jul 25 '18 at 12:28

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.