jquery ajax 文件上传,成功不被调用

jquery ajax file upload, success doesn't get called

本文关键字:成功 调用 ajax 文件 jquery      更新时间:2023-09-26

我正在使用jquery将图像上传到joomla站点,但是文件ajaxfileupload.js有问题。图像上传得很好,但"成功"中的函数不会被调用。我需要它来显示上传已完成的确认。我尝试使用"完成"而不是"成功",然后代码有效,但它会一遍又一遍地刷新页面。我怎样才能让它正常工作?这是代码..

upload: function (a) {
    if (jQuery("#Filedata-" + a).val() == "") {
        jQuery("#photoupload-" + a).remove();
        joms.uploader.upload();
        if (jQuery("#photoupload").next().length == 0) {
            joms.uploader.addNewUpload()
        }
        jQuery("#upload-photos-button").show();
        return
    }
    var c = (jQuery("#photoupload-" + a + " :input:checked").val() == "1") ? "&defaultphoto=1" : "";
    var b = jQuery("#photoupload-" + a).next().find(".elementIndex").val();
    b = (b != "") ? "&nextupload=" + b : "";
    jQuery("#photoupload-" + a).children().each(function () {
        jQuery(this).css("display", "none")
    });
    jQuery("#photoupload-" + a).append('<div id="photoupload-loading-' + a + '"><span class="loading" style="display:block;float: none;margin: 0px;"></span><span>' + joms.uploader.uploadText + "</span></div>");
    jQuery.ajaxFileUpload({
        url: this.postUrl + c + b,
        secureuri: false,
        fileElementId: "Filedata-" + a,
        dataType: "json",
        success: function (e, d) {
            jQuery("#photoupload-loading-" + a).remove();
            if (typeof (e.error) != "undefined" && e.error == "true") {
                jQuery("#photoupload-" + a).css("background", "#ffeded");
                jQuery("#photoupload-" + a).append('<span class="error">' + e.msg + "</span>")
            } else {
                jQuery("#photoupload-" + a).css("background", "#edfff3");
                jQuery("#photoupload-" + a).append('<span class="success">' + e.msg + "</span>")
            }
            jQuery("#photoupload-" + a).fadeOut(4500, function () {
                jQuery("#photoupload-" + a).remove();
                if (jQuery("#photoupload").next().length == 0) {
                    joms.uploader.addNewUpload()
                }
            });
            jQuery("#photoupload-" + a + " .remove").css("display", "block");
            if (e.nextupload != "undefined") {
                joms.uploader.upload(e.nextupload);
                return
            } else {
                jQuery("#upload-photos-button").show()
            }
        },
        error: function (f, d, g) {}
    });
    return false
}

我想我解决了这个问题。您必须删除选项:数据,数据类型。它会正常工作。

虽然这可能晚了,但对于第一次看到它的人来说,只是改变了 数据类型:"json",自 数据类型:"JSON",