I'm trying to manipulate the attributes of an object (access) using a variable, but I'm not getting it.
I tried to do the following:
$('#extruderAtual').text(obj.Printer1.extruder[0].tempRead);
basically it only changes the text of a given id
else {
var host = $('#host').val();
var printerName = $('#namePrinter').val();
var key = $('#key').val();
var url = host+'/printer/api/'+printerName+'apikey='+key+'&a=stateList&data={}';
$.ajax({
type: "GET",
url: url,
success: function (msg) {
var obj = JSON.parse(msg);
});
}
}
It's not insteressante to know how I get these variables, but how can I use them. In the variable url, I get the following link:
http://localhost:3344/printer/api/Printer1?apikey=e2ddc036-f883-460e-beb6-fc41026d720d&a=stateList&data={}
which in turn, returns something like this:
{"Printer1":{"activeExtruder":0,"debugLevel":6,"extruder":[{"error":0,"output":0,"tempRead":20.000000000000000,"tempSet":0.0000000000000000}]
my idea is to do something like this:
else {
var host = $('#host').val();
var printerName = $('#namePrinter').val();
var key = $('#key').val();
var url = host+'/printer/api/'+printerName+'apikey='+key+'&a=stateList&data={}';
$.ajax({
type: "GET",
url: url,
success: function (msg) {
var obj = JSON.parse(msg);
var printerName = $('#namePrinter').val();//I declare this variable again
alert(obj.printerName.extruder[0].tempRead);//give an alert only to show the expected integer value
});
}
}
But it does not work
Obs(it is not interesting to know how the variable printerName receives some value, in this code suppose that it has the same name as the link and passed: "Printer1")