Hello I have made a custom admin module, in which I am uploading image using using Ajax and for this I am using ajaxfileupload library.

this is my edit.php file code which uses ajax code-

class Assel_Character_Block_Adminhtml_Character_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {

    public function __construct() 
        $this->_objectId = 'id';
        $this->_blockGroup = 'character';
        $this->_controller = 'adminhtml_character';

        $this->_updateButton('save', 'label', Mage::helper('character')->__('Save Character'));
        $this->_updateButton('delete', 'label', Mage::helper('character')->__('Delete Character'));

        $this->_addButton('saveandcontinue', array(
            'label'     => Mage::helper('adminhtml')->__('Save And Continue Edit'),
            'onclick'   => 'saveAndContinueEdit()',
            'class'     => 'save',
        ), -100);

        $pathToMethod=$this->getUrl('*/*/fileUpload'); /*url of method in controller file to process on file or image*/

        $this->_formScripts[] = "var pathToMethod="."'".$pathToMethod."'";/*assign url of controller method in js variable to use in ajax below*/
        $script  = 

            function saveAndContinueEdit(){

                var btnUpload=$('#upload');
                var status=$('#status');

                new AjaxUpload(btnUpload, {
                    action:'pathToMethod', /*call the method in controller file in custom module*/
                    name: 'uploadfile',
                    onSubmit: function(file, ext){
                         if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 

                            status.text('Only JPG, PNG or GIF files are allowed');
                            return false;
                    onComplete: function(file, response){


                            $('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file).addClass('success');
                        } else{


        $this->_formScripts[] = str_replace(array("\r\n", "\r", "\n"), "", $script );


My problem is this Ajax call is giving the HTML of whole page of System->configuration in admin in response instead of calling method defined in controller.

What is wrong there in my code, somebody there to help me.?

2 Answers 2


There could be several things wrong here but your action for the Ajax would be a good place to start:

action:'pathToMethod' should be: action:pathToMethod

pathToMethod is a variable and should be used as one and not as a string.


Since the pathToMethod variable is created in PHP and you want to use it in the script you should probably echo or concatenate it to your script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.