PDA

View Full Version : Get response.status in load store



fabio.policeno
19 Sep 2012, 5:50 AM
Hello,

I've been trying to get the status code of the request that the store does, but without success .. in afterload sometimes have what I want, but not often. It seems that something is inside beforeload asynchronous:



beforeload: function(cp, operation)
{
console.log(operation.response.status)


Thank's!

redraid
19 Sep 2012, 6:30 AM
Try this:


store.load({
callback: function (records, operation, success) {
console.log('Status', operation.response.status);
}
});

Lunti
19 Sep 2012, 6:42 AM
Hello,

I've been trying to get the status code of the request that the store does, but without success .. in afterload sometimes have what I want, but not often. It seems that something is inside beforeload asynchronous:



beforeload: function(cp, operation)
{
console.log(operation.response.status)


Thank's!

The event "beforeload" is fired before load, where you have no answer from the server yet. ;)
Use "load" instead.

redraid
19 Sep 2012, 7:00 AM
Also you can do it with:


// add to store definition
lastOperation: null,
listeners: {
beforeload: function (store, operation) {
this.lastOperation = operation;
},
load: function () {
console.log('Status', this.lastOperation.response.status);
}
}

fabio.policeno
19 Sep 2012, 3:31 PM
The event "beforeload" is fired before load, where you have no answer from the server yet. ;)
Use "load" instead.
I understand and agree that logic, but it does not make much sense since the time while the response appears. Nor would this be because the parameter in this event if it does not bring me one operation ever.

fabio.policeno
19 Sep 2012, 3:33 PM
Also you can do it with:


// add to store definition
lastOperation: null,
listeners: {
beforeload: function (store, operation) {
this.lastOperation = operation;
},
load: function () {
console.log('Status', this.lastOperation.response.status);
}
}

Thanks even without test appears better than its previous solution, since the call store of the load may be internally in a ux, or at the time of sort, filter, etc.. So the ideal is to do in the same events. For this event we did an override in the store to pass the operation in load event and it worked perfectly. I think not including a failure to do this nativelyThank you!