Ashwani Panwar
Ashwani Panwar

Reputation: 4578

delete with ajax in admin panel magento

I want to perform delete operation with ajax in magento admin panel. I have created my own function deleteAttrGroupKey() and put it to controller GrouppricebackendController.php. I am trying to access deleteAttrGroupKey() function from my template(phtml) file but getting invalid path. code 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+"adminhtml/grouppricebackend/deleteAttrGroupKey",
        complete:function(){alert("completed");
          },
        success:function(event){
          alert("deleted"+event);
          }

        });
    }); 

how can I pass correct url for this ? Do I need to add deleteAttrGroupKey() function in config.xml ?

Upvotes: 0

Views: 696

Answers (1)

user3462934
user3462934

Reputation:

You should ajax request like this

new Ajax.Request("<?php echo $this->getUrl('adminhtml/grouppricebackend/deleteAttrGroupKey') ?>", {
           method: 'Post',
           parameters: {"id":attrKeyId},
           onComplete: function(transport) {

               alert(transport.responseText);

           }
       });

Yes you need to include deleteAttrGroupKey function in config.xml file

Upvotes: 1

Related Questions