Hi team
I have two buttons and want them to function like turning a light bulb on and off. What the buttons does currently on button whether the value is 0 or 1 takes as it an argument and update it to my channel. I only want to let the user if the button value is 1 should update once not twice, when the button is invoked from the browser. While off should not take that remaining value of on be updated to it, so what the code is doing and it does not look good to user experience.
// button click functionality here.
function BtnOff () {
$.ajax({
url: 'https://api.thingspeak.com/update?api_key=D**&field8=0',
type: 'GET',
data: {
format: 'text'
},
success: function (response) {
alert(response);
},
error: function () {
$('#error').text("There was an error processing your request.Please try again");
$('#singlebutton').append(data);
}
});
}
function BtnOn() {
$.ajax({
url: 'https://api.thingspeak.com/update?api_key=D**&field8=1',
type: 'GET',
data: {
format: 'text'
},
success: function (response) {
alert(response);
},
error: function () {
$('#error').text("There was an error processing your request.Please try again");
$('#singlebtn').append(data);
}
});
}

Ajay GohilRank #2,370 · 599 reputationPosted Nov 12, 2019, 10:50 PM EST