Bootstrap开关按钮切换不适用于Ajax调用Thingspeak频道

我有bootstrap切换按钮,它不适用于我的Ajax呼叫请求。基本上,我希望按钮在加载到服务器后自动打开。这样它可能会更新到我的Thingspeak频道,因此按钮会在单击按钮之前更新,并且不会更新一次。

同时我还希望关闭开关以关闭我的Ajax呼叫请求,以便它可能不会将其更新为我的Thingspeak通道的0值。

如何完成这种逻辑?为了做到这一点,引导开关按钮可能是UI的一种很好的方法,但是我的客户端服务器似乎工作不正常。

<div class="form-group"><br>
  <div class="col-md-3 text-center">
  <input type= "checkbox" data-toggle = "toggle" 
    data-onstyle="success" id="switch-state">
  </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) {},});
        }

        )
biao12319880808 回答:Bootstrap开关按钮切换不适用于Ajax调用Thingspeak频道

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3116716.html

大家都在问