Magento 1.9 – How to Get Custom Module Controller URL

ajaxgeturlmagento-1.9

I have custom admin page edittab.phtml in that page I have ajax call

function deleteOldLens(id)
{
    var url = "<?php echo $this->getUrl('/customtabs/ajax/deletelens');?>";
    new Ajax.Request(url, {
        method:'post',
        parameters: {
            id: id
        }
        , requestHeaders: {Accept: 'application/json'},
        onSuccess: function(transport) {
            retjson = transport.responseText.evalJSON();
            alert( retjson.resp );
        }
    }); 
}

and in module customtabs/controllers/ajaxController.php I have deletelensAction().This code gives me error like

   http://localhost/optishop/index.php/admin/customtabs/ajax/key/c86e7acf7f7d45339bf50a7ab6efc4b2/?isAjax=true
   404 Not found

I have also tried other solutions like

  Mage::app()->getStore()->getUrl('*/ajax/deletelens');
  Mage::app()->getUrl('customtabs/ajax/deletelens')     

Best Answer

You should use

var url = "<?php echo
$this->getUrl('customtabs/ajax/deletelens/');?>";

Note the removal of the first /.

Related Topic