简体   繁体   中英

anonymous function, add parameters

I use in my Ajax.Request my jsp. (Prototype)

Somehow I can pass extra parameters in the anonymous function onComplete?

For example,

function save() {
    var pars = "param1=date";
    new Ajax.Request('algo.ctr', {
        parameters: pars,
        onComplete: f,
    });
}
var f = function (e) {
    alert(e.status);
}

I want to use parameter e but also other.

I do not want to use global variables.

The idea is to run multiple concurrent requests and when each one finishes doing something with an element that I put.

Generally you cannot "add parameters" to the Prototype function's native signature. But you can do something like this:

function mySuccessFunction( a, b, c ) {
  alert( "Success!" + a + b + c ) ;
}

new Ajax.Request(url, {
  method: 'get',

  parameters: {company: 'example', limit: 12} // use an object literal
  // for parameters, not a query string

  onSuccess: function( transport ) {
    mySuccessFunction( transport, 'param1', 'param2' ) ;
  }
});

Note here I've passed parameters as an object literal and attached to the onSuccess event instead of the onComplete event.

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