如何使用插件上的按钮在 jquery ajax 中调用 thingspeak api?

how to call thingspeak api in jquery ajax using a button on your plugin?

嗨,团队,我无法向我创建的频道发送请求,我在 Jquery ajax 上有以下代码。我的客户端频道没有任何反应。;

我从这个逻辑中到底遗漏了什么,请帮助我,我的按钮似乎没有对我的频道发出任何呼叫请求。

<script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> 
  $(document).ready(function){
    $.ajax({
      url:'https://api.thingspeak.com/channels/YYY/fields/field8/last.txt?api_key=XXX',
      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);
      }
    });

  });

</script>

你不能在已经有 src

<script> 标签中加入代码

所以你的:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> 
   $(document).ready(function){...
</script>

应该是:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
   $(document).ready(function){...
</script>

您使用的 URL 格式不正确。

尝试:https://api.thingspeak.com/channels/YYY/fields/8/last.txt?api_key=READAPIKEY

替换为您的频道号并读取密钥。