Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am struggling to communicate with my plugin button, i am using thingspeak channel and have a channel that has a field. I am struggling to send a request on a client side in jquery, as i am using 'GET' method.

What I have tried:

HTML
<html>
<head>

  <!-- 
  
  NOTE: This plugin will not be visible on public views of a channel. 
        If you intend to make your channel public, consider using the
        MATLAB Visualization App to create your visualizations.
  
  -->  

  %%PLUGIN_CSS%%
  %%PLUGIN_JAVASCRIPT%%
  
</head>
<body>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"><br/>
  
<div class="col-md-4 text-center"> 
<button id="singlebutton" name="singlebutton" class="btn btn-primary">IOT-Talk</button> 
</div>
</body>
</html>


JavaScript
<script
src="https://code.jquery.com/jquery-3.3.1.js"integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="crossorigin="anonymous"></script>
<script type="text/javascript">
function OPENDOOR() {
           $.ajax({
               url:"https://api.thingspeak.com/apps/plugins.json?api_key=MF710NTKMG0E44UG",
               type: 'GET',
               success: function(data) {
               //called when successful
                 //console.log(data);
                 $('#singlebutton').on('click', function (e) {
                  $('#singlebutton').append(data);
                 })
             }
                                     
           });
       }
Posted
Updated 5-Nov-19 21:51pm
v2
Comments
Herman<T>.Instance 6-Nov-19 3:50am    
Why not use a POST?
gcogco10 6-Nov-19 4:26am    
POST method does not allow me, as it show status message on POSTMAN "page you looking for does not exist". the documentation from thingspeak uses GET to access the channel either for reading, https://www.mathworks.com/help/thingspeak/readlastfieldentryage.html. I want to read the last field name i created on my channel. On my channel dashboard no update to see the data.
Herman<T>.Instance 6-Nov-19 5:35am    
OK.
your part script type .... function ....

That part should be just above < /body>. You are then sure all HTML is loaded properly so the script can find all controls
gcogco10 6-Nov-19 7:29am    
I have fixed it, it can communicate back to my channel. the issue i was not getting it right. was ajax call function for parsing my channels. eg. https://api.thingspeak.com/update?api_key=D****&field8=0

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900