jQuery-File-Upload done callback

11,683

Remove the line "dataType: 'json'," and change "data.result.files" by "data.files" in the "done" callback and it works !

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

wilfryed

Updated on June 04, 2022

Comments

  • wilfryed
    wilfryed almost 2 years

    I'm trying to use blueimp's file upload, and -like a lot of people- I can't figure why the done callback doesn't work!

    The file upload works well (I use the php upload handler) even if the fail callback send a fail issue. I've read a lot of topics about the json problems, but no answer fit my problem.

    Here's my javascript code :

    $(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');
    });
    

    Do you have a solution or something to test to find some errors?

    EDIT1: the success callback works only when I use dataType: 'text'

    EDIT2: Here's is the response when the complete callback is triggered:

    {"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:\\/\\/[email protected]\\/SITE\\/acces_web\\/inner\\/upload-image\\/server\\/php\\/files\\/IMG_0060.jpg\",\"thumbnailUrl\":\"http:\\/\\/[email protected]\\/SITE\\/acces_web\\/inner\\/upload-image\\/server\\/php\\/files\\/thumbnail\\/IMG_0060.jpg\",\"deleteUrl\":\"http:\\/\\/[email protected]\\/SITE\\/acces_web\\/inner\\/upload-image\\/server\\/php\\/?file=IMG_0060.jpg\",\"deleteType\":\"DELETE\"}]}","status":200,"statusText":"OK"}
    
  • wilfryed
    wilfryed about 9 years
    Thank you for your help, but that's not effective.