PDA

View Full Version : [Solved] data.Store problem



fedelman
4 Aug 2007, 9:10 PM
Guys, I've got a data.Store like that:



var myds = new Ext.data.Store
(
{
proxy: new Ext.data.HttpProxy
(
{
url: 'http://foo.bar/list'
}
),
reader: new Ext.data.JsonReader
(
{
root: 'posts',
totalProperty: 'count',
id: 'id'
},
[
{name: 'title', mapping: 'title'},
{name: 'timestamp', mapping: 'timestamp'},
{name: 'post', mapping: 'post'}
]
),
remoteSort: true
}
);
myds.setDefaultSort('timestamp', 'desc');};
What happen if the target URL (http://foo.bar/list) not exists, timeout, return an invalid data or another fail option?


How can I catch this error and display in a Ext.MessageBox.alert()?

I use this ds in a grid.

Thanks,
Fede

mystix
4 Aug 2007, 9:32 PM
http://extjs.com/deploy/ext/docs/output/Ext.data.Store.html#event-loadexception

TheNakedPirate
9 Aug 2007, 8:29 PM
How do I show the response body in the message box.



ds.on('loadexception', function(httpProxy, o , response) {
Ext.MessageBox.show({
title:'An Exception has occurred',
msg: 'The server has encountered a problem and is unable to retrieve your data.' + response,
buttons: Ext.Msg.OK
});
} );All I get is [object]

mystix
9 Aug 2007, 10:11 PM
you'll need to inspect the response object via FireBug and pull out what you need from there.

TheNakedPirate
10 Aug 2007, 12:55 AM
yeah i'm looking at it but I don't understand how to read the response object in javascript (not an expert on this kinda thing)

I'm using monorail and setting the response to 500 (exception) and rendering the Exception.Message to the response body.

how do I just pick up whats in the response body and splat it to a messagebox

BernardChhun
10 Aug 2007, 3:04 AM
alert(response.responseText);

TheNakedPirate
10 Aug 2007, 12:33 PM
thanks i'll give that a go

TheNakedPirate
22 Aug 2007, 4:52 PM
The solution I ended up with was this.

Thanks for the help



this.dataSource.on('loadexception', function(httpProxy, o , response) {
Ext.MessageBox.show({
title:'An Exception has occurred',
msg: 'The server has encountered a problem and is unable to retrieve your data.<br/><font color="red">' + response.responseText + '</font>',
buttons: Ext.Msg.OK
});
} );