我在我的应用程序中广泛使用 $.(ajax) 函数来调用 ASP.net Web 服务。我想编写一个包装器以集中所有 ajax 调用。我找到了几个简单的解决方案,但没有一个解决将参数传递给代表的问题,例如,如果我有:
$.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();
}
});
此调用的包装器必须能够将 someOtherParam1、someOtherParam2 传递给 OnSuccess 委托......除了将变量打包到通用数组中之外,我想不出其他解决方案。
你们是如何解决这个问题的?