fnServerData

fnServerData

bot2600bot2600 Posts: 3Questions: 0Answers: 0
edited October 2009 in General
Good morning,

Had a quick question about fnServerData. I have the following:

aoData.push({
"name": "variable1", "value": $('#control1').val(),
"name": "variable2", "value": $('#control2').val(),
"name": "variable3", "value": $('#control3').val(),
"name": "variable4", "value": $('#control4').val()
} );
The issue I see is that no matter what order I put them in, only the last thing passed actually gets to the server (so in this case I would have a value for variable4 but the other 3 would be null.

Question is, am I doing it wrong or can I pass only one variable? I would think that isnt the case because it is defined as name value pairs, which infers multiples. I have no doubt this is a problem between my chair and my keyboard.

I appreciate any help!

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi bot2600,

    The reason that isn't working for you is that you are redeclaring the 'name' and 'value' properties 3 times. For example it might be like doing:

    var i=1;
    i=2;
    i=3;
    i=4;
    alert(i);

    and expecting the alert to show all four values of i :-).

    As such, what I think you will need to do is something like:

    aoData.push({ "name": "variable1", "value": $('#control1').val() });
    aoData.push({ "name": "variable2", "value": $('#control2').val() });
    aoData.push({ "name": "variable3", "value": $('#control3').val() });
    aoData.push({ "name": "variable4", "value": $('#control4').val() });

    Regards,
    Allan
  • bot2600bot2600 Posts: 3Questions: 0Answers: 0
    Thanks, that sorted the issue. I appreciate the quick response!
This discussion has been closed.