I have a basic collection that does a fetch on document ready: ie:
message_list.fetch({
success: function(){
console.log('success');
//render
grid_view.render();
},
error: function(xhr, text, ajax){
//set a column limit and retru
console.log('retrying');
urlParams.colLimit = true;
$.ajax(this);
return;
},
data: urlParams,
processData:true
});
This grabs a json from the server, which is querying an hbase table with thrift. With certain accounts the dataset in hbase is too large and it runs out of memory and returns a 500 response. So I want to refire the same ajax call on error after I add a new query param. Looking at the jquery .ajax documentation it says to call $.ajax(this), but this is the window object. Also the xhr variable has empty success function. How do I refire the same ajax call with the same properties and success/error functions?
It’s pretty easy — make an object that you store and can pass back in:
As long as the
fetch_optionsis defined in the same scope as the two callback functions, andfetch_optionsis accessible outside of that scope, anything that can accessfetch_optionscan use it as it’s arguments to.fetch.