Reputation: 1274
How it is possible to customize the parameter list in an ajax call.
i.e.
At times this:
$.ajax({ url: TheURL, data: { par1:VAR_A, par2:VAR_B, par3:VAR_C} });
At other times this:
$.ajax({ url: TheURL, data: { par4:VAR_D, par5:VAR_E} });
And at other times this:
$.ajax({ url: TheURL, data: { par6:VAR_F} });
etc.
Thanks,
David
Upvotes: 0
Views: 134
Reputation: 781058
Put the parameters in a variable.
var params = { par1:VAR_A, par2:VAR_B, par3:VAR_C};
// or
var params = { par4:VAR_D, par5:VAR_E};
// or
var params = { par6:VAR_F};
$.ajax({ url: TheURL, data: params });
You could put your AJAX call in a function, then call it with the appropriate parameters:
function do_ajax(params) {
$.ajax({ url: TheURL, data: params });
}
do_ajax({ par6:VAR_F});
// or
do_ajax({ par4:VAR_D, par5:VAR_E});
Upvotes: 2