I use $.(ajax) function extensively in my app to call ASP.net web services. I would like to write a wrapper in order to centralize all the ajax calls. I found few simple solutions, but none address an issue of passing parameters to delegates, for example, if i have:
$.ajax({
type: "POST",
url: "http://localhost/TemplateWebService/TemplateWebService/Service.asmx/GetFoobar",
data: jsonText,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
var results = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
OnSuccess(results, someOtherParam1, someOtherParam2);
},
error: function(xhr, status, error) {
OnError();
}
});
The wrapper to this call would have to have the way to pass someOtherParam1, someOtherParam2 to the OnSuccess delegate...Aside from packing the variables into a generic array, I can't think of other solutions.
How did you guys address this issue?