Gcobani Mkontwana

Gcobani Mkontwana

  • 558
  • 1.9k
  • 397.7k

How to make your button reads your data?

Nov 27 2019 12:18 AM
Hi Team
 
I have this following code, it swich being enabled and disabled. Now i want to find a way if it is enable it must reads my data on thingspeak channel, using rest api key. Example below,
  1. <input type="checkbox" data-toggle="toggle" data-on="Enabled" data-off="Disabled">  
  2. <input type="checkbox" id="toggle-two">  
  3. <script> $(function()  
  4. { $('#toggle-two').bootstrapToggle({ on: 'Enabled', off: 'Disabled' }); })  
  5. $.ajax({  
  6. url:'https://api.thingspeak.com/update?api_key=DLQ0F7W5FGVO1I9Q&field8=0',  
  7. type:'GET',  
  8. data:{  
  9. format:'text'  
  10. },  
  11. success:function(response) {  
  12. alert(response);  
  13. },  
  14. error:function(){  
  15. $('#error').text("There was an error processing your request.Please try again");  
  16. $('#singlebutton').append(data);  
  17. }  
  18. });  
  19. }  
  20. </script>  
Can anyone help me to improve this code better please, thanks.

Answers (1)