在Internet Explorer中未完成jQuery更改事件代码

时间:2015-01-24 18:46:29

标签: jquery internet-explorer

下面的代码在Chrome,Firefox和Safari中正常运行,但在IE中却没有(我使用的是IE 9)。前三个浏览器执行所有代码,因此显示alert1和alert2。奇怪的是在IE警报1中显示,但alert2不是(并且还没有执行其余的代码)。这是怎么回事?

    $("#btnUpload").change(function () {
        alert("alert1");
        var data = new FormData();
        alert("alert2");
        data.append("dummybestandsnaam", $("#btnUpload").get(0).files[0]);
        $.ajax({
            url: "FileUploadHandler.ashx?vllid=" + $("#txtVllID").val(),
            type: "POST",
            data: data,
            contentType: false,
            processData: false,
            //START
            xhr: function () {
                var xhr = new window.XMLHttpRequest();
                xhr.upload.addEventListener("progress", function (evt) {
                    if (evt.lengthComputable) {
                        var percentComplete = evt.loaded / evt.total;
                        percentComplete = parseInt(percentComplete * 100);
                        $("#divpb").progressbar({ value: percentComplete });
                    }
                }, false);
                return xhr;
            },
            //EINDE
            beforeSend: function () { $("#divpb").show() },
            error: function (err) { },
            success: function (result) {
                //loze parameter aan url meegeven is noodzakelijk omdat anders de image niet ververst vanwege cache
                var d = new Date();
                $.ajax({
                    url: "get_img_thumb.ashx?vllid=" + $("#txtVllID").val() + "&r=" + d.getTime(),
                    datatype: "image/jpg",
                    success: function (data) {
                        var d2 = new Date();
                        $("#imgUploaded").attr("src", "get_img_thumb.ashx?vllid=" + $("#txtVllID").val() + "&r=" + d2.getTime());
                    }
                });
                //$("#divGelukt").show("slow", function () { });
            },
            complete: function () { $("#divpb").hide() }
        });
    });

代码段HTML

<label class="myLabel">
    <input type="file" ID="btnUpload" accept="image/*" />
    <span>Wijzig foto</span>
</label>

1 个答案:

答案 0 :(得分:0)

IE9不支持Formdata。 有用的链接:

相关问题