3

How do I go about adding extra parameters on the call back function?

eg.

function callback(data){
    alert(data.message);
}

And you would call it by Dajaxice.examples.args_example(callback, {'text':$('#text').val()}

what if I want to add an extra parameter in the callback function

function callback(data, flag){
    alert(data.message);
    if (flag){ /* do something */}
}

Currently I have a work around like this:

Dajaxice.examples.args_example(function(data){
    callback(data, true);
}, {'text':$('#text').val()});

Is there a better way or official way to do it in dajaxice?

James Lin
  • 25,028
  • 36
  • 133
  • 233

2 Answers2

0

Am I correct to assume this flag will depend on something from within the ajax function?

If so, could you not pass your flag as a part of the returned json?

function callback(data) {
    alert(data.message);
    if (data.flag) { /* do something */}
}
Farmer Joe
  • 6,020
  • 1
  • 30
  • 40
0

In your ajax.py file:

def my_ajax_func(... my_args ...):
...
    my_message = "Hello world!"
    my_flag = True
    return simplejson.dumps({'message':my_message, 'flag':my_flag})

In your javascript callback function:

function callback(data){
    alert(data.message);
    if (data.flag){ /* do something */}
}
Roland
  • 103
  • 1
  • 1
  • 7