mykes
31 Mar 2008, 6:25 PM
Correct me if I'm wrong...
I suggest that a retry() method be added to the Ext.Ajax class. As implemented, if you want to implement retry, you end up doing something recursive, which can cause your javascript serious problems:
var retry_count = 10;
function do_request() {
Ext.Ajax.request({
url: some_url,
success: function(response, obj) {
... whatever you do when it succeeds
},
failure: function(response, obj) {
if (--retry_count > 0) {
// retry!
do_request(); // again! (Recurse)
}
else {
alert('error!');
}
}
});
}
As you can see, the do_request() call inside the failure handler is going to recurse 10 times. If you don't limit it, it could recurse too many times you get a browser error. It's creating up to 10 nested closures and Ext.Ajax objects, too.
If retry() is implemented, there would be no recursion:
Ext.Ajax.request({
retries: 10,
url: some_url,
success: function(response, obj) {
... whatever you do when it succeeds
},
failure: function(response, obj) {
if (--obj.retries > 0) {
// retry!
retry(); // again! (but not recursive!)
}
else {
alert('error!');
}
}
});
The retry() method would also be useful if you are simply doing the same ajax request many times. An example might be an RSS reader that uses Ajax to request updates from the server periodically; the Ajax request would be identical each "poll."
I suggest that a retry() method be added to the Ext.Ajax class. As implemented, if you want to implement retry, you end up doing something recursive, which can cause your javascript serious problems:
var retry_count = 10;
function do_request() {
Ext.Ajax.request({
url: some_url,
success: function(response, obj) {
... whatever you do when it succeeds
},
failure: function(response, obj) {
if (--retry_count > 0) {
// retry!
do_request(); // again! (Recurse)
}
else {
alert('error!');
}
}
});
}
As you can see, the do_request() call inside the failure handler is going to recurse 10 times. If you don't limit it, it could recurse too many times you get a browser error. It's creating up to 10 nested closures and Ext.Ajax objects, too.
If retry() is implemented, there would be no recursion:
Ext.Ajax.request({
retries: 10,
url: some_url,
success: function(response, obj) {
... whatever you do when it succeeds
},
failure: function(response, obj) {
if (--obj.retries > 0) {
// retry!
retry(); // again! (but not recursive!)
}
else {
alert('error!');
}
}
});
The retry() method would also be useful if you are simply doing the same ajax request many times. An example might be an RSS reader that uses Ajax to request updates from the server periodically; the Ajax request would be identical each "poll."