Upload file: response Text returns undefined value in IE browser

View: New views
2 Messages — Rating Filter:   Alert me  

Upload file: response Text returns undefined value in IE browser

by Ho Thong Nhat :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everybody,

At this moment, I am encountering an issue I have not found the way to solve yet. Please give me a clue if

you can. Many thanks in advance!

I am developing a module allowing users to upload image file to server with CodeIgniter and YUI. There

are some restrictions for this upload: image files only, .GIF, JPG, ... and the maximum capacity for the

uploaded file not exceed 1 Megabyte.  And the following is my JS code:

function uploadPhoto()
{

    setGlobalMessage("");
    var sURL = _APBMRootURL + "adminMembers_controller/uploadPhoto";

    var callback =
    {
        upload: handleUploadPhotoUpload,
        failure: handleUploadPhotoFailure
    };

    var f = document.getElementById("frm_Main");
    var postData = YAHOO.util.Connect.setForm(f, true);
    var request = YAHOO.util.Connect.asyncRequest('POST', sURL, callback);

}

function handleUploadPhotoUpload(o)
{
    //alert(o.reponseText);
    if (o.responseText == undefined || o.responseText == null)
    {
        setGlobalMessage("Connection timeout. Please try again later.");
        ///setGlobalMessage("The size for the uploaded image should not exceed 1Mbs.");
        return;
    }
    ...
}

function handleUploadPhotoFailure(o)
{
    .....
}

In IE, I got o.responseText with undefined value whenever I upload the file with the capacity larger than the

 allowed maximum capacity as I mentioned above.

While I do not get this issue in Firefox.

Many thanks for your assistance!

Best Regards,

Nhat


     

Re: Upload file: response Text returns undefined value in IE browser

by mattatlamplight :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

A couple of points: I'm not sure if they'll help with the immediate problem, though!

1. I don't think the upload case ever calls a failure handler - they all go to upload (check http://developer.yahoo.com/yui/connection/#upload)
2. It's not clear if you're using an SSL connection, but if so you'll need the third argument in setForm set to true:
var postData = YAHOO.util.Connect.setForm(f, true, true);
3. test for undefined using ===, rather than ==
4. o.responseText should be what's in the iframe that's used for the upload (see the docs linked above), but I'm not sure of the detail of this.  Is the filesize enforcement at the form or server?  That may affect things.  What does your server return if the file is too big?

Hope that's helpful, but may not be!

Matt

--- In ydn-javascript@..., false <htnhat@...> wrote:

>
> Hello everybody,
>
> At this moment, I am encountering an issue I have not found the way to solve yet. Please give me a clue if
>
> you can. Many thanks in advance!
>
> I am developing a module allowing users to upload image file to server with CodeIgniter and YUI. There
>
> are some restrictions for this upload: image files only, .GIF, JPG, ... and the maximum capacity for the
>
> uploaded file not exceed 1 Megabyte.  And the following is my JS code:
>
> function uploadPhoto()
> {
>
>     setGlobalMessage("");
>     var sURL = _APBMRootURL + "adminMembers_controller/uploadPhoto";
>
>     var callback =
>     {
>         upload: handleUploadPhotoUpload,
>         failure: handleUploadPhotoFailure
>     };
>
>     var f = document.getElementById("frm_Main");
>     var postData = YAHOO.util.Connect.setForm(f, true);
>     var request = YAHOO.util.Connect.asyncRequest('POST', sURL, callback);
>
> }
>
> function handleUploadPhotoUpload(o)
> {
>     //alert(o.reponseText);
>     if (o.responseText == undefined || o.responseText == null)
>     {
> setGlobalMessage("Connection timeout. Please try again later.");
> ///setGlobalMessage("The size for the uploaded image should not exceed 1Mbs.");
> return;
>     }
>     ...
> }
>
> function handleUploadPhotoFailure(o)
> {
>     .....
> }
>
> In IE, I got o.responseText with undefined value whenever I upload the file with the capacity larger than the
>
>  allowed maximum capacity as I mentioned above.
>
> While I do not get this issue in Firefox.
>
> Many thanks for your assistance!
>
> Best Regards,
>
> Nhat
>