Search code examples
imageuploadextjs3

ExtJs3. Defect when the upload file


To upload a file using inputType: 'file', and for a form prescribed fileUpload: true. Everything works fine, the file is saved. But after saving the file block success (from ajax request) is not satisfied. Ie all the stops to waitMsg: 'Saving Data ...'.

What could be wrong?


Solution

  • Also, remember to set the Content-Type header to correct MIME type in your server response: "text/html". Anything else will result in ExtJS throwing an error when decoding your response.

    In PHP, this can be done with

    <?php    
        header('Content-type: text/html');
        echo json_encode(array('success' => true));
    ?>
    

    From ExtJS API docs:

    If the server is using JSON to send the return object, then the Content-Type header must be > set to "text/html" in order to tell the browser to insert the text unchanged into the document body.

    Characters which are significant to an HTML parser must be sent as HTML entities, so encode > "<" as "<", "&" as "&" etc.

    Make sure you do escape special HTML characters as suggested. If you don't, ExtJS may still succeed in parsing the server response but with unexpected twists: single quotes in HTML-like strings turn into "', etc.