我正在努力使用Thingspeak导出时间范围内的数据,但尚无此逻辑的示例。我想在我的频道中使用Thingspeak导出时间范围内的数据。下面是我对具有API的ajax调用的datetimepicker和jquery的逻辑。
<body>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"><br>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" />
<!---DatePicker---->
<div class="container">
<div class='col-md-4'>
<div class="form-group">
<div class='input-group date' id='datetimepicker6'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class='col-md-4'>
<div class="form-group">
<div class='input-group date' id='datetimepicker7'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
<!---Downloading File using
Jquery with Buttons---->
<div class="form-group"><br>
<div class="col-md-1.9 text-center">
<button id="download" name="download" class="btn btn-warning" >Download</button><br>
</div>
</div>
<!---Button functionality---->
<br>
<div class="form-group"><br>
<div class="col-md-2 text-center">
<button id="singlebutton" name="singlebutton" class="btn btn-danger">Off</button><br>
</div>
</div>
<br/>
<div class="form-group"><br>
<div class = "col-md-2 text-center">
<button id = "singlebtn" name="singlebtn" class="btn btn-success">On</button><br>
</div>
</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.6/moment.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script>
// date functionality
$(document).ready(function() {
$(function() {
$('#datetimepicker6').datetimepicker();
$('#datetimepicker7').datetimepicker({
useCurrent: false
});
$("#datetimepicker6").on("dp.change", function(e) {
$('#datetimepicker7').data("DateTimePicker").minDate(e.date);
});
$("#datetimepicker7").on("dp.change", function(e) {
$('#datetimepicker6').data("DateTimePicker").maxDate(e.date);
});
});
});
// button click functionality here.
$(document).ready(
function () {
$.ajax({
url: 'https://api.thingspeak.com/update?api_key=D**&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=D***&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);
}
});
}
);
// Downloading file into zip file.
$(document).ready(function() {
$("#download").click(function() {
$.ajax({
url:'https://api.thingspeak.com/update?api_key=D***&field8=1',
type:'GET',
success:function(response){
window.location = response;
}
});
});
});