I'm wanting to create a system of APIs (within a single object) within javascript all of which stem from jQuery's ajax function but I want to be able to pass an override "success" function to be triggered like so:
function Eidos(){
this.api = function(data, success){
$.ajax({
type: 'POST',
url: '/api',
data: data,
success: function(rData){
return rData;
}
})
};
this.refreshInfo = function(id, success){
log.info('refreshed page id: '+ id);
return this.api({'command': 'refresh', 'pageid': id}, success);
}
};
In this example, I just want to "refresh" info (pull in new text data or what have you). I already have a sever-side page setup.
And I'd be calling it up like so:
$('.refresh').click(function(){
$("#myModal").modal('show');
var id = $(this).data('ei');
var api = eidos.refreshInfo(id, function(){
$("#myModal").modal('hide');
});
return false;
});
Obviously this doesn't work (btw, the object was already created via var eidos = new Eidos(); ), however, Idk how to implement it. I want the success: function to behave differently on different pages so I'll need an override but I'm not sure how to make that work here.