tags:

views:

113

answers:

1

I'm using ajaxSend() to intercept requests originating from a jQuery plugin on my page and then filtering irrelevant requests using the ajaxOptions url.

$('some-selector').ajaxSend(function(e, xhr, settings) {
    var ajaxUrl = settings.url;
    if (ajaxUrl.search('targetpage.aspx') == 0) {
         //need to add an additional parameter to my request here
    } 
}

I need to insert an additional parameter into relevant requests. Is it possible to modify the request at this point?

A: 

You could append the parameter to the settings.data hash by checking that it is not null before:

if (settings.data == null) {
    settings.data = { };
}
settings.data['param'] = 'value';

or just modify the url:

settings.url += (settings.url.match(/\?/) ? "&" : "?") + 'param=value';
Darin Dimitrov
Darin, I tried appending my parameter to settings.url (without success) before I posted the question. While I used a workaround to solve my initial problem (I hooked into the plugin to modify the url before the request is sent), I'd still like to know why I'm drawing a blank with this method.
Noel Sequeira