I am getting a little stuck with this one. I am trying to use jquery on my website to change an element. Without using an array of data in JSON, it works fine but soon as I use an array of data in there, it stops working. I have tried multiple searches online and tested around myself but I can't seem to get it to work. Surely it should be as simple as below? (I am passing data into this so the server can get commands back if you wondered what the x is for. This bit works fine.)
The following is simple version of the JSON data I am working with:
{"OUTPUTA":"TRUE","OUTPUTB":"TRUE"},{"OUTPUTC":"FULSE","OUTPUTD":"TRUE"}
Script used:
function update(x) {
$.getJSON('/_ConfigJSON', {
buttondata: x,
}, function (data) {
$("#BUTTONA").text(data.[1][OUTPUTA]);
}
});
}
"OUTPUTA":"TRUE","OUTPUTB":"TRUE","OUTPUTC":"FULSE","OUTPUTD":"TRUE"
Script used:
function update(x) {
$.getJSON('/_ConfigJSON', {
buttondata: x,
}, function (data) {
$("#BUTTONA").text(data.OUTPUTA);
}
});
}
Your code is syntactically incorrect.
Here's the updated code:
function update(x) {
$.getJSON('/_ConfigJSON', {
buttondata: x,
}, function (data) {
// Gets the second element.
$("#BUTTONA").text(data[1]["OUTPUTA"]);
}
});
}