Magento 1.9 – How to Call Custom Module Controller for Ajax

magento-1.9

I am trying to call the custom modules controller function for ajax call, Can any tell me how to get the URL. This is my controller function,

class Spritz_RequestQuotation_IndexController extends Mage_Core_Controller_Front_Action
{
   public function emailquoteAction(){

   }
}

This code I am using to get URL, Its giving 404 not found.

<?php echo $this->getUrl('spritz_requestquotation/IndexController/emailquote') ?>

This is my JS code.

var formId = 'quotation_form';
var myForm = new VarienForm(formId, true);
var postUrl = '<?php echo $this->getUrl('spritz_requestquotation/IndexController/emailquote') ?>';
function doAjax() {
    if (myForm.validator.validate()) {
        new Ajax.Updater(
            { success:'formSuccess' }, postUrl, {
                    method:'post',
                    asynchronous:true,
                    evalScripts:false,
                    onComplete:function(request, json) {
                    Element.hide(formId);
                    Element.show('formSuccess');
                    setTimeout(function(){ 
                        var inst = jQuery('[data-remodal-id=quoteform]').remodal();
            inst.close();
                    }, 2000);
                },
                onLoading:function(request, json){
                    Element.show('formLoader');
                },
                parameters: $(formId).serialize(true),
            }
        );
    }
}

new Event.observe(formId, 'submit', function(e){
    e.stop();
    doAjax();
});

Best Answer

You need to change from IndexController to index. Like this:

<?php echo $this->getUrl('spritz_requestquotation/index/emailquote') ?>
Related Topic