Gcobani Mkontwana

Gcobani Mkontwana

  • 1.5k
  • 282
  • 7.9k

Toggle button does not work

Nov 13 2019 12:35 AM
Hi Team
 
I have created a switch button, toggle button and it seem not working. Meaning i want my button when it switch on must send an update to my channel to thingspeak and when it switch off must do the same. Please help me to achieve this logic, thanks.
 
<!---Button functionality---->
<br>
<div class="form-group"><br>
<div class="col-md-3 text-center">
<input type= "checkbox" data-toggle = "toggle" data-onstyle="success">
</div>
</div>
// button click functionality here.
$(document).ready(
function() {
$.ajax({
url:'https://api.thingspeak.com/update?api_key=DLQ0F7W5FGVO1I9Q&field8=1',
type:'GET',
data:{
format:'text'
},
success:function(response) {
alert(response);
},
error:function(xhr,status, errorThrown) {
console.log("There was an error processing your request" + errorThrown);
console.log("Status:" + status);
console.log(xhr);
},
complete:function(xhr,status) {},
});
}
)
 

Answers (5)