如何将params添加到GET ajax请求中?

时间:2014-01-23 00:22:45

标签: javascript jquery ajax

我正在尝试更改ajax请求中使用的url,如:

$(document).ajaxSend(function(event, jqXHR, ajaxOptions) {
    var pattern = /page=\d+/g;
    if (ajaxOptions.type == 'GET' && pattern.test(ajaxOptions.url)) {
        if (Drupal.settings.views_infinite_scroll.hasOwnProperty('drupal_html_id')) {
            for (var key in Drupal.settings.views_infinite_scroll.drupal_html_id[0]) {
                ajaxOptions.url = ajaxOptions.url + '&drupal_html_id[]=' + key + ';' + Drupal.settings.views_infinite_scroll.drupal_html_id[0][key];
            }
        }
    }
    console.log(ajaxOptions.url, 'ajaxOptions.url');
});

ajax请求从这里开始(来自jquery.autopager插件):

  

$。get(nextUrl,insertContent);

但是nextUrl总是保持不变(没有任何更改它会发送到服务器),即使我确定调用ajaxSend回调并且 ajaxOptions.url被正确改变.....

1 个答案:

答案 0 :(得分:0)

好的,这个函数在jQuery 1.7中正常工作...而不是在1.4.4