1

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

1
  • Is fld a string? Are you sure you want to get send POST data to HTML page? Commented Jun 7, 2010 at 7:41

3 Answers 3

1

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);
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

0

you need to modify the following line.

data: { fld:fld, id: id },

1 Comment

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..
0
var data = { id : id };
data[fld] = value;

$.ajax({ ..., data : data });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.