jQuery-文件-上传完成回调

jQuery-File-Upload done callback

我正在尝试使用 blueimp 的文件上传,并且 - 像很多人一样 - 我不明白为什么 done 回调不起作用!

文件上传效果很好(我使用 php 上传处理程序),即使失败回调发送失败问题。我已经阅读了很多关于 json 问题的主题,但没有答案适合我的问题。

这是我的 javascript 代码:

$(function () {
'use strict';
var url = 'server/php/';
$('#fileupload').fileupload({
    url: url,
    dataType: 'json',
    done: function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<p/>').text(file.name).appendTo('#files');
        });
    },
    fail: function (data) {
        alert("Fail!");
    },
    progressall: function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css(
            'width',
            progress + '%'
        );
    }
}).prop('disabled', !$.support.fileInput)
    .parent().addClass($.support.fileInput ? undefined : 'disabled');
});

您是否有解决方案或可以测试以发现错误的东西?

EDIT1:成功回调仅在我使用 dataType: 'text'

时有效

EDIT2:这是触发完成回调时的响应:

{"readyState":4,"responseText":"
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in       /home/mesdevis/work/SITE/acces_web/inner/upload- image/server/php/UploadHandler.php on line 299
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 780
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 804
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in  /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 806
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 809
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 812
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 815
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 819
\n
 \nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 822
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 826
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 832
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 885
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 905
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 963
\n
\nWarning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 1048
\n
\nWarning: Cannot modify header information - headers already sent by (output started at /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php:299) in  /home/mesdevis/work/SITE/acces_web/inner/upload-image/server/php/UploadHandler.php on line 1120
\n{\"files\":    [{\"name\":\"IMG_0060.jpg\",\"size\":55277,\"type\":\"image\/jpeg\",\"url\":\"http:\/\/wilfried@work.wilfryed.com\/SITE\/acces_web\/inner\/upload-image\/server\/php\/files\/IMG_0060.jpg\",\"thumbnailUrl\":\"http:\/\/wilfried@work.wilfryed.com\/SITE\/acces_web\/inner\/upload-image\/server\/php\/files\/thumbnail\/IMG_0060.jpg\",\"deleteUrl\":\"http:\/\/wilfried@work.wilfryed.com\/SITE\/acces_web\/inner\/upload-image\/server\/php\/?file=IMG_0060.jpg\",\"deleteType\":\"DELETE\"}]}","status":200,"statusText":"OK"}

尝试将已完成的移动到通话的末尾

$.ajax({url: '/'}).done(function(data) {});

对于您的代码,它类似于:

$('#fileupload').fileupload({
    url: url,
    dataType: 'json',
    success: function (data) {
        alert("Success!");
    },
    progressall: function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css(
            'width',
            progress + '%'
        );
    }
})
.done(function (e, data) {
        $.each(data.result.files, function (index, file) {
            $('<p/>').text(file.name).appendTo('#files');
        });
    )
.prop('disabled', !$.support.fileInput)
    .parent().addClass($.support.fileInput ? undefined : 'disabled');
});

删除行 "dataType: 'json'," 并在 "done" 回调中将 "data.result.files" 更改为 "data.files" 并且有效!

dataType: 'json',
        done: function (e, data) {
            $.each(data.files, function (index, file) {
                $('<p/>').text(file.name).appendTo('#files');
            });
        },