I have this json info:
data.ContactName
data.ContactEmal
data.Departement
I Would like to have a function like that
function GetMyVal(myStringKey)
{
$.Ajax
,...
, ...
,success :function(data)
{
$("#mytarget").val(data.myStringKey);
}
}
Call Like that GetMyVal("ContactName");
Try changing:
$("#mytarget").val(data.myStringKey);
to:
$("#mytarget").val(data[myStringKey]);
Here is what those constructs mean:
$("#mytarget").val(SOMETHING);
change the value of the element with id "mytarget" to SOMETHING
data.myStringKey
take the object named "data" and give me the value of its property named literally "myStringKey"
data[myStringKey]
take the object named "data" and give me the value of its property named like a value of the variable named "myStringKey"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With