Click here to Skip to main content
14,364,399 members
Rate this:
Please Sign up or sign in to vote.
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>
<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>


<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 22:51pm
v2
Comments
digimanus 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.
digimanus 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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100