How to Submit Admin Ajax Form in Magento

0
87
views
Advertisement

Here, I am explaining about How to Submit Admin Ajax Form using magento default ajax functionality. In Below Code You just need to Replace “FORM_ID_HERE” With your form id and you also replace “YOUR_ACTION_HERE” to your action.

<script type="text/javascript">

 var myForm = new varienForm('FORM_ID_HERE');
    var formId = 'FORM_ID_HERE';
    var postUrl = '<?php echo $this->getUrl('*/*/YOUR_ACTION_HERE') ?>';
    function doAjax() {
        if (myForm.validator.validate()) {
            new Ajax.Updater(
                { success:'formSuccess' }, postUrl, {
                    method:'post',
                    asynchronous:true,
                    evalScripts:false,
                    onComplete:function(response, json) {
 Element.hide('loading_mask_loader');
 var container = $('YOUR_CONTAINER_ID_HERE');
 var content = response.responseText;
 container.update(content);
                        
                    },
                    onLoading:function(response, json){
                        Element.show('formLoader');
                    },
                    parameters: $(formId).serialize(true),
                }
            );
        }
    }
    
    new Event.observe(formId, 'submit', function(e){
        e.stop();
        doAjax();
    });

</script>

Thanks for reading my blog. I hope it will help you, Please leave your comments here if it’s really help you. 🙂

Thank You :),
Mayank Zalavadia