how to call controller with jquery ajax magento
ajax, magento
Solution
use this
<script type="text/javascript">
function callController(){
new Ajax.Request("<?php echo $this->getUrl('groupprice/adminhtml_grouppricebackend/index') ?>", {
method: 'Post',
parameters: {"parameter_name":"value"},
onComplete: function(transport) {
alert(transport.responseText);
}
});
}
Problem
I have created custom module in magento, I want to access controller using jquery ajax but I am not finding correct method for doing this. Ajax code in template is ``` jQuery(".deleteAttrKeyId").on("click",function(){ var baseUrl="<?php echo Mage::getBaseUrl();?>"; var idArr=this.id.split("-"); attrKeyId=idArr[1]; alert(this.id); jQuery.ajax({ type: "POST", dataType: "JSON", data :{'id':attrKeyId}, url :baseUrl+"groupprice/adminhtml_grouppricebackend/index", complete:function(){alert("completed"); }, success:function(result){ alert(result); } }); }); ``` Block code in layout is ``` <groupprice_adminhtml_grouppricebackend_index> <reference name="content"> <block type="groupprice/adminhtml_grouppricebackend" name="grouppricebackend" template="groupprice/grouppricebackend.phtml"/> </reference> </groupprice_adminhtml_grouppricebackend_index> ``` Controller code is ``` <?php class Group_GroupPrice_Adminhtml_GrouppricebackendController extends Mage_Adminhtml_Controller_Action { public function indexAction() { echo __FILE__; } } ```