PDA

View Full Version : [FIXED][2.x] File upload and XML response not work together



Evolic
20 Aug 2008, 7:33 AM
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:

<?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:

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:

// 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:


processResponse : function(response){
this.response = response;
if(!response.responseText &&!response.responseXML){
return true;
}
this.result = this.handleResponse(response);
return this.result;
},

evant
5 May 2009, 8:54 AM
Remember seeing this before. Fixed in SVN.