Search code examples
javascriptjqueryfile-uploadtimerswfupload

serverData not returning correctly in internet explorer - swfupload and rails


We are using SWFUpload for one of our forms so people can upload media. Once SWFUpload dispatches the uploadSuccess event, we get the data and URL of the file from the serverData that gets passed back when the event is dispatched.

Currently, in IE, the event is dispatched but it doesn't seem like the information is saving -- our hidden fields where we put the server data are blank. Perhaps the event is hanging and being dispatched too early, and then the server data is still empty.

The particular function that is supposed to snag and save the data:

.bind('uploadSuccess', function(event, file, serverData){
    var swfu = $.swfupload.getInstance('#swfupload-control');
    try {
        file.id = "singlefile";
        if (serverData === " " || serverData === null) {
            swfu.customSettings.upload_successful = false;
        } else {
            swfu.customSettings.upload_successful = true;
            document.getElementById("hidFileID").value = serverData;
        }
    } catch (ex) {
        swfu.debug(ex);
    }
})

If serverData is empty, is it possible to check for that data again with an event handler function?


Solution

  • FWIW, it's not possible because it's an event handler function, which is what I assumed.

    There's an interesting possibility here of using GET instead of POST for better cross-browser compatibility: SWFUpload works in IE, but not in Firefox, however, I'm uploading to S3 so that solution is not possible.

    I'm attempting to get Uploadify up and running to see what happens there.

    UPDATE:

    I switched to Uploadify, but the issue wasn't gem-specific. The data WAS getting returned for IE. However, this line:

    document.getElementById("hidFileID").value = serverData;
    

    was putting the serverData, which is a string of XML markup, into a hidden <input> tag. IE was not allowing this because the input tag is not a block element, so you can't insert markup into non-block elements.

    Firefox and Chrome "forgive" this, but IE is actually correct here.

    I ended up parsing the serverData in the javascript and inserting the string (the url) that I needed from the data into the hidden input field, instead, and everything worked.