I’m writing a jQuery plugin where I can send data trough $.post method and I would like to set the name of the var name passed via ajax object http://api.jquery.com/jQuery.post/:
$('#selector').pluginName({url:'url.com/searches', var_name:'myVarName'});
my problem is I can’t set a name via var_name because it is passed as var name itself
var name = settings.var_name;
$.post(settings.url, {name:next_search}, settings.callback);
if I send this example i send {'name':'data'} instead of {'myVarName':'data'}.
how can I fix this?
The jquery Ajax method just takes an array for the data argument and there’s lots of ways of creating that array.
If you want to add an item where the key is in a variable then you can add it directly.