Question

I'm having trouble with the code below. The script sends 2 variables and a file to a php-script to upload it to a server. In Firefox and Chrome everything runs smoothly but in Opera I get "ReferenceError: Undefined variable: FormData".

Can't test in IE or Safari because I'm using the File API. There's other functions in the script but only these 2 are important because the error is caused here.

datumActiviteit = "testxx";
naamActiviteit = "testyy";

function sendFiles() {
try{
    var imgs = document.querySelectorAll(".obj");
    for (var i = 0; i < imgs.length; i++) {
        new BestandenUploaden(imgs[i],imgs[i].file);
    }
}
catch(ex){alert(ex);}

}

function BestandenUploaden(img,file){
try{
    var formData = new FormData();
    formData.append("activiteit", naamActiviteit);
    formData.append("datum", datumActiviteit);
    formData.append("bestand", file);


    var oXHR = new XMLHttpRequest();
    oXHR.open("POST", "launcherV2.php");

    oXHR.onreadystatechange = function (oEvent) {
        if (oXHR.readyState==4 && oXHR.status==200) {
            if (oXHR.responseText == "continue") {
                img.parentNode.lastChild.style.opacity = "1.0";
                img.parentNode.lastChild.style.backgroundColor = "transparent";
                img.parentNode.lastChild.style.backgroundImage = "url(../afbeeldingen/rocket/complete.png)";
            }
            else {
                window.alert(oXHR.responseText);
            }
        }
        else{
            window.alert("readyState or status error :", oXHR.statusText);
        }
    };

    oXHR.send(formData);

}
catch(err){alert(err)};


};

Does anyone have a clue why only Opera(v11.62) would throw this error?

Was it helpful?

Solution

FormData is only available in Opera v12 and up: http://caniuse.com/#search=FormData

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top