Skip to content
Loading
 
0
  • 0
    Hi Jefferson
     
    Ok that could work, but the problem is can my both button be trigger during an Ajax call request? 
    0
  • Jefferson S. Motta
    0
    "both button be trigger during an Ajax call request"? Sorry, why is that?
    0
  • 0
    I meant to say will my both buttons work, with this new logic implemented? on my tag attribute for html i reference tag ID and on my  function in javascript, i am using those for onclick invoke.
    0
  • Jefferson S. Motta
    0
    Yes, they will work, can't you test before production?
    0
  • 0
    Hi Jefferson
     
    Ok the field8=0 does work, but now field8=1 should update only once, it does not. Need to figure it that out based on this new implementation. Meaning field8=1 on my URL from Ajax call should do the call once, so that can view this request on my channel on thingspeak, only field8=0 does that. 
    0
  • Jefferson S. Motta
    0
    Hi, can you share your code again to analyze?
    0
  • 0






     
     
     
     
    // button click functionality here.
    $(document).ready(
    function () {
    $.ajax({
    url: 'https://api.thingspeak.com/update?api_key=DLQ0F7W5FGVO1I9Q&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() {
    $.ajax({
    url: 'https://api.thingspeak.com/update?api_key=DLQ0F7W5FGVO1I9Q&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);
    }
    });
    }
    );
     What the code now, it only those fields, but the field8=1 must update once so that i can view that update from my channel on thingspeak. I can only see field8=0 for my channel, so its missing so logic again. Please assist i am almost there as to say, thanks.
    0
  • Jefferson S. Motta
    0
    remove your API KEY from the POST :0
    0
  • 0
    As the field8=0? But do you know i am writing this API key to my channel? standard procedure for thingspeak in writing channel? I  will try
    0
  • Jefferson S. Motta
    0
    "but now field8=1 should update only once, it does not", but its update once so, but twice?
    0
  • 0
    field8=1 only now does not update, before it was updating twice. the requirement that it should update once because the state of the button is true(1) not null(0) off button. I hope i making sense here. My logic should be similar when turning a light when it is on and when it is off, it shoulbe off completely. What we trying to do here is the same real problem for bulb scenario.
    0
  • Jefferson S. Motta
    0
    I was thinking about GET or POST in your Ajax, and I found this:
     
    If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.
     
    at https://stackoverflow.com/questions/715335/get-vs-post-in-ajax 
     
    so try use POST, instead GET:  
     
    1. type: 'POST',  
    0
  • 0
    Hi Jefferesen
     
    Well i dont know, but sure bit by bit we are getting somewhere. Before i was not able to get any response only authentication not being found, 404 status. Now see below, response is the same with field8=0, field8=1. But now field8=1 does not update or send message to my tera term as being 1. Will show you both screen shots;
     
     Its the same with my channel, as to say if my back end behaves the same as front end;
     
     
     
     
     
     
    0
  • Jefferson S. Motta
    0
    I don't know how you are testing this page.
     
    But, try to init the project and click on the "On", close and click on the "Off", because probably your end-user will not click both.
     
    Let me know. 
    0
  • 0
    i am using Visual studio code, using rest client to test my API request.
    0
  • Jefferson S. Motta
    0
    Just try to create a production environment for your test.
    0