Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
$(ajax)Jquery包装器-将参数传递给代理_Jquery_Ajax_Parameter Passing - Fatal编程技术网

$(ajax)Jquery包装器-将参数传递给代理

$(ajax)Jquery包装器-将参数传递给代理,jquery,ajax,parameter-passing,Jquery,Ajax,Parameter Passing,我在应用程序中广泛使用$.ajax函数调用ASP.net web服务。我想写一个包装器来集中所有ajax调用。我发现很少有简单的解决方案,但没有一个解决向代理传递参数的问题,例如,如果我有: $.ajax({ type: "POST", url: "http://localhost/TemplateWebService/TemplateWebService/Service.asmx/GetFoobar", data: jsonText,

我在应用程序中广泛使用$.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委托……除了将变量打包到通用数组中,我想不出其他解决方案


你们是如何解决这个问题的?

我也有同样的问题。我的解决方法是将参数包含在数据变量中,然后将其从该变量中拉出。成功时的数据/错误/完成。 当返回this.data时,它看起来像foo=1&bar=2&baz=3,因此您需要将参数解析出来

$.ajax({
  url: 'blah.html',
  data: {foo:1,someOtherParam1:2,someOtherParam2:3},
  success: function(data) {
    var params = this.data.split("&");
    OnSuccess(results, params[1].split("=")[1], params[2].split("=")[1]);
  }
});

请确保您没有收到此消息。数据与成功函数返回的数据变量混淆…

问题在于缺乏透明度,我发布此消息是为了了解其他ppl如何处理类似情况。如果您有几个参数怎么办?您是否有类似于此的.data.param1、此.data.param2等内容?没有。此.data返回时看起来像foo=1&bar=2&baz=3,因此您必须解析字符串并将其拉出。