簡體   English   中英

jQuery ajax文件上傳,成功未調用

[英]jquery ajax file upload, success doesn't get called

我正在使用jquery將圖像上傳到joomla網站,但是文件ajaxfileupload.js出現問題。 圖像上傳就好了,但是沒有調用“成功”中的函數。 我需要它來顯示上傳完成的確認信息。 我嘗試使用“ complete”而不是“ success”,然后代碼可以工作,但是它會不斷地刷新頁面。 如何使它像預期的那樣工作? 這是代碼。

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
}

我想我解決了問題。 您必須刪除以下選項:data,datatype。 它將正常工作。

雖然這可能已經很晚了,但是對於第一次看到它的人來說,只需將dataType:“ json”更改為dataType:“ JSON”,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM