function liveUpdate(fld,value,id) {
$.ajax({
type: 'POST',
url: 'myurl.html',
data: { fld:value, 'id': id },
success: function(data){//console.log(data);
}
});
}
i want fld to be posted as fld's value not the variable name fld? i've tried to wrap around with eval but no luck
any ideas?
thanks
asked Jun 7, 2010 at 7:36
Alessandro
3852 gold badges8 silver badges24 bronze badges
3 Answers 3
You could do something like this:
function liveUpdate(fld, value, id) {
var data={id: id};
data[fld]=value;
$.ajax({
type: "POST",
url: "myurl.html",
data: data,
success: function(data) {
//console.log(data);
}
});
}
answered Jun 7, 2010 at 7:46
icktoofay
130k23 gold badges261 silver badges239 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
you need to modify the following line.
data: { fld:fld, id: id },
answered Jun 7, 2010 at 7:40
Adeel
19.3k4 gold badges48 silver badges60 bronze badges
1 Comment
Alessandro
doesnt work.. the value of fld that i am passing to the funciton is eg. product_name (can be different), value is 'toaster' i want it so when i post (goign to a Coldfusion script) i have a variable called product_name = toaster and not fld = toaster.. i can update the server side code if not possible, but prefer not to..
var data = { id : id };
data[fld] = value;
$.ajax({ ..., data : data });
answered Jun 7, 2010 at 7:46
Comments
lang-js
flda string? Are you sure you want to get send POST data to HTML page?