views:

399

answers:

2

Hi,

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

A: 

Did you respect the constraint written in the doc ?

IMPORTANT: For all values EXCEPT html and xml, The server response should be an HTML file with a textarea element. The response data should be inside the textarea element. Using an HTML document is the only reliable, cross-browser way this transport can know when the response has loaded. For the text/html (Or XML) mimetype, just return a normal HTML/XML document. In other words, your services for JSON and Text formats should return the data wrapped as the following:

Philippe
Yeah I've made sure that it's within the textarea tags, but as still failing. Going to go through the code with a fine tooth comb to see if I can find any silly mistakes again..
Grant Collins
A: 

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.

Alex Cheng
Thanks for this after some major digging it was the backend process sending some really strange stuff back and that was causing the element to fail. Thanks.
Grant Collins