0

我正在使用 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
}
4

2 回答 2

5

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

于 2013-06-22T10:20:21.310 回答
0

虽然这可能已经晚了,但对于第一次看到这个的人来说,只需将 dataType: "json", 更改为 dataType: "JSON",

于 2017-03-31T18:31:21.593 回答