When clicking the flic button, I want to have an HTTP makeRequest GET function, save some of the information in a global variable, and use this variable in an HTTP makeRequest POST function.
I am able to create a variable and change it during the GET function. However, the information is not saved and when I use the POST function, it uses the value the variable had during the initialization phase.
This is the code:
var runNumber = -1 // my global variable
buttonManager.on("buttonSingleOrDoubleClickOrHold", function(obj) {
var button = buttonManager.getButton(obj.bdaddr);
var clickType = obj.isSingleClick ? "click" : obj.isDoubleClick ? "double_click" : "hold";
http.makeRequest({
url: urlGet,
method: "GET",
headers: {"Content-Type": "application/json"},
}, function(err, res) {
console.log("request status: " + res.statusCode);
runNumber = 5 // changing the variable
});
http.makeRequest({
url: urlPost,
method: "POST",
headers: {"Content-Type": "application/json"},
content: JSON.stringify({"Units":15, "Run Number":runNumber}),
}, function(err, res) {
console.log("request status: " + res.statusCode);
});
The code above is not working the way I expected it to work. The run number in the post function stays -1 although I change it to 5 in the get function.
Please advise and thank you