PDA

View Full Version : XML AJAX request on Components



naxito
26 May 2009, 12:32 AM
Hi all.

Has anything change on Ajax Request on Components such as Grid or Combos from 2.2.1 release?
I do following request fro a grid.


grid = new Ext.grid.GridPanel({
store: new Ext.data.GroupingStore({
reader: this._config.reader,
proxy: new Ext.data.HttpProxy({
url: sapCaller,
method: 'POST',
xmlData: xml,
headers: {
'Content-Type': 'text/xml'
}
}),
sortInfo: {
field: this._config.storeField.sort,
direction: "ASC"
},
groupField: this._config.storeField.group
}),
columns: this._config.columns,
view: new Ext.grid.GroupingView({
forceFit: true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
sm: this._sm,
tbar: toolbar,
frame: false,
width: window.screen.availWidth,
height: 600,
collapsible: false,
animCollapse: false,
renderTo: this._config.renderTo,
loadMask:true
})

that generates the following request, with a correct response, using Ext 2.2.1.


url: http://XXXXXXXXX/Caller.asp
Date Tue, 26 May 2009 08:26:05 GMT
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
Pragma no-cache
Content-Type text/xml; Charset=UTF-8
Expires Tue, 26 May 2009 08:25:04 GMT
Cache-Control no-cache
Transfer-Encoding chunked

But using Ext 3.0 rc1. I get this request and response.


http://XXXXX/Caller.asp?_dc=1243324725606&xaction=load
Request:
Date Tue, 26 May 2009 07:58:46 GMT
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
Pragma no-cache
Content-Type text/html
Expires Tue, 26 May 2009 07:57:46 GMT
Cache-Control no-cache
Transfer-Encoding chunked
Response
An error from server

However using a Ext.Ajax.request, I got a correct request and response on Ext 3.0 Rc1.


Code
Ext.Ajax.request({
url: sapCaller,
method: 'POST',
xmlData: xml,
headers: {
'Content-Type': 'text/xml'
},
scope: this,
success: function(response){
var xml = response.responseXML;
}

});

Response
http://XXXXXXXXX/SAPCaller.asp
Date Tue, 26 May 2009 08:00:19 GMT
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
Pragma no-cache
Content-Type text/xml; Charset=UTF-8
Expires Tue, 26 May 2009 07:59:16 GMT
Cache-Control no-cache
Transfer-Encoding chunked


As you may notice, the posible error is on the header content-type, although i have set up it on HttpProxy, that is not set to text/xml. Is this a bug, or I have to do anything more?

Animal
26 May 2009, 12:41 AM
There's an error on the server. Why?

naxito
26 May 2009, 1:03 AM
I send to server the following XML.


<XML><SERVICE>get_wflist#es_wfhr</SERVICE><PARAMS><language>S</language><consulta>listaAll</consulta
><tipoWF/></PARAMS></XML>

and in CALLER.asp.


var nodeRoot;
var aRequest=new Array();
var sRequest=new String();
var XMLDoc=Server.CreateObject("Microsoft.XMLDOM");
XMLDoc.load(Request);
var sXML=XMLDoc.xml;
oXML=Server.CreateObject("Microsoft.XMLDOM");
oXML.loadXML(sXML);
aRequest[0]=getLogonUser();
aRequest[1]=oXML.selectSingleNode("//XML/SERVICE").text; <- error


and server cannot process it, because xml is not sent.

I think, it is not a server error, because with Ext 2.2.1. works fine. Buy maybe I am wrong.

PS: I know that is not the usual way to work with AJAX, but I inherited this infrastructure

Animal
26 May 2009, 1:14 AM
But there's an error from the server! Investigate that! What is the error? That's what is causing the problem you see.

naxito
26 May 2009, 1:38 AM
Hi again...

I have just noticed another thing.
Using Ext 2.2.1. the method is POST but on Ext 3.0 is GET. Using FireBug I get info you can see on attachments.

And I think the solution is here
http://www.extjs.com/forum/showthread.php?t=67680&highlight=POST+GET&page=2

I will check it.

thanks Animal for keep me investigating.

Animal
26 May 2009, 2:10 AM
So the server doesn't like GET, and was returning a 500.

I think there was a bug in RC1.1 which was causing GET to be used by mistake.

naxito
26 May 2009, 3:04 AM
I have solved it.
I have applied this patch to HttpProxy.doRequest


doRequest : function(action, rs, params, reader, cb, scope, arg) {
var method = (this.api[action]) ? this.api[action]['method'] : undefined;
var o = {
params : params || {},
method: method,
request: {
callback : cb,
scope : scope,
arg : arg
},
reader: reader,
callback : this.createCallback(action, rs),
scope: this
};
//.......
}

That i have found here http://www.extjs.com/forum/showthread.php?p=326093#post326093

then I modified my creation of object HttpProxy to


new Ext.data.HttpProxy({
api:{load:{url:sapCaller,method:'POST'}},
url: sapCaller, //keep to maintain compatibility with Ext 2.2.1 may generates errors...
method: 'POST',//keep to maintain compatibility with Ext 2.2.1 may generates errors...
xmlData: xml,
headers: {
'Content-Type': 'text/xml'
}
});


But I had to modify also HttpProxy.buildUrl, because it returns an object instead of a string.


buildUrl : function(action, record) {
record = record || null;
var url = (this.api[action]) ? this.api[action].url : this.url;
if (!url) {
throw new Error('HttpProxy tried to build an url for the action "' + action + '" but could not find an api definition for this action or an url to fall-back to. Please review your proxy configuration.');
}

if (this.prettyUrls === true && record instanceof Ext.data.Record && !record.phantom) {
url += '/' + record.id;
}
return url;
},


I am not sure about its collateral effects, and maybe it is related to
http://www.extjs.com/forum/showthread.php?t=67922

Could you,Animal, confirm it?