1. #1
    Sencha User
    Join Date
    Sep 2007
    Location
    Poland, Cracow
    Posts
    70
    Vote Rating
    0
    Evolic is on a distinguished road

      0  

    Exclamation [FIXED][2.x] File upload and XML response not work together

    [FIXED][2.x] File upload and XML response not work together


    Hello all,
    at the beginning I want to write some background information:

    Background information
    In my application I'm using XML documents to provide communication between server (PHP) and client (JS).
    XML file looks like this one:
    HTML Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <response success="true">
      <action>getProfile</action>
      <logs>
        <log type="Notice" action="GetProfile" msg="Done"/>
      </logs>
      <data>
        <settings>
          <id>1</id>
          <login>admin</login>
          <status>1</status>
          <fname>Default</fname>
          <surname>Admin</surname>
          <fullname>Default Admin</fullname>
        </settings>
        <roles>
          <admin>true</admin>
          <editor>true</editor>
          <user>true</user>
        </roles>
      </data>
    </response>
    <!--
    Page generation time: 1.708 sec.
    -->
    In XML file I'm sending all information from server:
    - data
    - error/message information (logs)
    - security information (no authorization for some action)
    - info about not valid fields
    - etc

    I changed default XmlReader to process my own XML format.
    All works fine.

    Recently I wanted to add image support, so I need to upload some images.
    But there is a problem.

    Problem background
    It is very difficult to debug file upload response, because it is not standard Ajax request.
    In Firebug it is shown on Net tab, but I couldn't see valid response,
    because Firefox doesn't cache XML files.
    I'm using HttpFox also, but results are the same.
    After many hours fighting with debugging I finally found the main problem.
    Fiddler turned out helpful with file upload debugging.

    XML files can be sended with following content types:
    - text/html (no response.responseXML in Firefox)
    - text/xml (works fine)
    - application/xml (works fine)

    BUG
    In file upload example you used JSON output. It is working fine.
    But the problem is when I want to use XML output here.

    In file upload case, instead of standard AJAX request, there is used method:
    Ext.data.Connection.doFormUpload(o, ps, url)
    Inside it there is function cb(), which returns following object:
    Code:
                var r = {  // bogus response object
                    responseText : '',
                    responseXML : null
                };
    The problem is in case of XML file, there is no responseText!

    In abstract class Ext.form.Action there is private function:
    Code:
        // private
        processResponse : function(response){
            this.response = response;
            if(!response.responseText){
                return true;
            }
            this.result = this.handleResponse(response);
            return this.result;
        },
    The problem is if there is no response.responseText this function returns true,
    and there is no possible response handling e.g. error processing (with this.form.errorReader)

    Solution
    I think you should change above function to this:
    Code:
        processResponse : function(response){
            this.response = response;
            if(!response.responseText &&!response.responseXML){
                return true;
            }
            this.result = this.handleResponse(response);
            return this.result;
        },

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,067
    Vote Rating
    660
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Remember seeing this before. Fixed in SVN.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Thread Participants: 1