简体   繁体   中英

How to add params to GET ajax request?

I am trying to alter url used on ajax request like:

$(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 request starts here (from jquery.autopager plugin):

$.get(nextUrl, insertContent);

but nextUrl always remains the same(without any change it goes to server), even if I am sure that ajaxSend callback is invoked and
ajaxOptions.url is altered properly.....

好的,此功能按预期在jQuery 1.7中起作用...在1.4.4中不起作用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM