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

问题描述 投票:-1回答:2

您好,我无法向我创建的频道发送请求,我在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>
jquery matlab api channel
2个回答
0
投票

您无法在<script>标记中包含已经具有src的代码

所以您:

<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>

0
投票

您正在使用的URL格式不正确。

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

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

© www.soinside.com 2019 - 2024. All rights reserved.