PDA

View Full Version : Login: form with XML response



algarpe
4 Oct 2007, 7:04 AM
Hi everybody,

I'm trying to complete my login script, but I don't know how to read the XML response from my jsp page :((. My code is based in another one which reads from a JSON. I'm blocked at the handler function which gets the XML response.

My code:


hiddenForm.submit({
waitTitle: 'Accessing',
waitMsg: 'Please wait...',
url: 'login.jsp',
method: 'POST',
success: fsws,
failure: fswf,
params:{
user: user.getValue(),
pwd: enpwd
}
});

fsws = function(f,a){
if (!a || !a.result || !a.result.user){
Ext.MessageBox.alert(_title, "Error: didn't get the awaited result!");
return;
}
res = a.xmlData;
}

fswf = function(f,a){
if (a && a.result && a.result.msg) {
Ext.MessageBox.alert("", a.result.msg);
} else {
Ext.MessageBox.alert("", "Didn't finish the athentication process!");
}
}
The other code, in fsws took values like this: a.result.user
How can I get it from a XML like this one?

<response success="true"><login>OK</login><user>user</user><password>pwd</password></response>

Anyone can help me?

Thanks very much =;

Bye

fay
4 Oct 2007, 7:41 AM
It's not too difficult:


fsws = function(f,a){

var xml = a.response.responseXML.childNodes[0];
if (xml.getAttribute('success') == 'true')
{
var dq = Ext.DomQuery;

var Login = dq.selectValue('login', xml);
var User = dq.selectValue('user', xml);
var Password = dq.selectValue('password', xml);
}
}

See also: DomQuery (http://extjs.com/deploy/ext/docs/output/Ext.DomQuery.html)

algarpe
4 Oct 2007, 10:23 PM
Hi fay,

thank you very much.

=D>