【问题标题】:Add additional parameter to get/post ajax添加附加参数以获取/发布 ajax
【发布时间】:2012-01-06 11:56:58
【问题描述】:

是否可以在 jQuery 中为 get/post 方法添加一些额外的参数。

例如:

$.get(url,{a:b,c:d},function(data){

//codes..

});

这里你可以看到它包含两个参数,a和c。

现在认为我需要在网页中的每个 get/post 方法中添加一个附加参数 [e:f]

这可能吗?

所以当我们触发 get/post 方法时,它需要自动添加一个额外的参数。

谢谢。

【问题讨论】:

    标签: javascript jquery html post get


    【解决方案1】:

    您可以使用jQuery.ajaxSetup() 设置默认值。

    jQuery.ajaxSetup({
        data: {
            e: f // obviously `f` needs to be defined in this scope
        }
    });
    

    但是,您应该知道,如果您使用.load(),这些参数将不会包括在内,因为很可能是bug in jQuery

    【讨论】:

      猜你喜欢
      • 2020-02-13
      • 2011-04-08
      • 2014-01-20
      • 2012-03-02
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多