Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dojo.io.iframe erroring when uploading a file

Hit an interesting problem today when trying to upload an image file < 2MB using dojo.io.iframe.

My function to process the form is called, but before the form is posted to the server I am getting the following error:

TypeError: ifd.getElementsByTagName("textarea")[0] is undefined

My function that is used to action the post of the form is :

function uploadnewlogo(){

var logoDiv = dojo.byId('userlogo');
var logoMsg = dojo.byId('uploadmesg');

//prep the io frame to send logo data.
dojo.io.iframe.send({
    url: "/users/profile/changelogo/",
    method: "post",
    handleAs: "text",
    form: dojo.byId('logoUploadFrm'),
    handle: function(data,ioArgs){

        var response = dojo.fromJson(data);


        if(response.status == 'success'){

            //first clear the image
            //dojo.style(logoDiv, "display", "none");
            logoDiv.innerHTML = "";

            //then we update the image
            logoDiv.innerHTML = response.image;

        }else if(response.status == 'error'){

            logoMsg.innerHTML = data.mesg;

        }else{              

            logoMsg.innerHTML = '<div class="error">Whoops! We can not process your image.</div>';
        }

    },
    error: function(data, ioArgs){

        logoMsg.innerHTML = '<div class="error">' + data + '</div>';

    }
});

}

The form is very basic with just a File input component and a simple button that calls this bit of javascript and dojo.

I've got very similar code in my application that uploads word/pdf documents and that doesn't error, but for some reason this does.

Any ideas or pointers on what I should try to get this to work without errors?

Oh I'm using php and Zend framework for the backend if that has anything to do with it, but I doubt it as it's not even hitting the server before it fails.

Many thanks,

Grant

like image 523
Grant Collins Avatar asked Oct 14 '22 07:10

Grant Collins


2 Answers

Another common reason for this error is the server isn't packaging the data correctly. This means even if you have set "handleAs: json" you have to send that json wrapped in some html. This is what it should look like:

<html>
    <body>
        <textarea>
            { payload: "my json payload here" }
        </textarea>
    </body>
</html>

Your error was saying it couldn't find the textarea in your return from the server. For more look at http://docs.dojocampus.org/dojo/io/iframe

like image 139
ace Avatar answered Oct 27 '22 00:10

ace


Since the load handler of dojo.io.iframe.send() has been triggered, the request should have been sent to the server and response is back. I think the response from server is not correct. Maybe the server returns an error page.

Use Firebug to inspect current page's DOM and find the transporting iframe created by Dojo and check its content. Firebug can capture iframe I/O too, check its Net tab. You may find the root cause of this issue.

like image 35
Alex Cheng Avatar answered Oct 27 '22 00:10

Alex Cheng