$.(ajax) wrapper for Jquery - passing parameters to delegates

Posted by gnomixa on Stack Overflow See other posts from Stack Overflow or by gnomixa
Published on 2010-05-14T17:00:45Z Indexed on 2010/05/14 17:04 UTC
Read the original article Hit count: 327

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX