innostudio / fileuploader

Beautiful and powerful HTML file uploading tool. A jQuery, PHP and Node.js plugin that transforms the standard input into a revolutionary and fancy field on your page.
141 stars 25 forks source link

Unexpected EOF for JSON Parse #56

Closed gienq closed 4 years ago

gienq commented 4 years ago

Hey, I'm implementing FileUploader for my private, personal site based on CodeIgniter Framework and I'm getting error: JSON Parse error: Unexpected EOF in this line of my script:

ajax.onload = function()
                    {
                        form.classList.remove( 'is-uploading' );
                        if( ajax.status >= 200 && ajax.status < 400 )
                        {
                            var data = JSON.parse( ajax.responseText );
                            form.classList.add( data.success == true ? 'is-success' : 'is-error' );
                            if( !data.success ) errorMsg.textContent = data.error;
                        }
                        else alert( 'Error. Please, contact the webmaster!' );
                    };

but the file uploads itself and as a response from backend I have:

{
    "hasWarnings": false,
    "isSuccess": true,
    "warnings": [],
    "files": [{
        "date": "Fri, 26 Jun 2020 11:57:46 +0200",
        "extension": "jpg",
        "file": "public\/uploads\/kazali (19).jpg",
        "format": "image",
        "name": "kazali (19).jpg",
        "old_name": "kazali.jpg",
        "old_title": "kazali",
        "replaced": false,
        "size": 52036,
        "size2": "50.82 KB",
        "title": "kazali (19)",
        "type": "image\/jpeg",
        "uploaded": true
    }]
}

So the JSON response is valid. Why do I get EOF error?

gienq commented 4 years ago

Oops I forgot to make response in PHP backend. It's working.