我已经获得了以下Jquery代码,该代码通过ajax发送到web服务,以接收填充2个仪表的数据。它在页面加载上有用,但我希望它每5分钟运行并更新一次。我该怎么办?
我的代码是: -
$(document).ready(function(){
$.ajax({
type: "POST",
url: "CarService.asmx/GetResponseTime",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var TicketResponse = response.d;
var opts = {
lines: 12, // The number of lines to draw
angle: 0.05, // The length of each line
lineWidth: 0.44, // The line thickness
pointer: {
length: 0.75, // The radius of the inner circle
strokeWidth: 0.035, // The rotation offset
color: '#374767' // Fill color
},
limitMax: 'false', // If true, the pointer will not go past the end of the gauge
colorStart: '#67c2ef', // Colors
colorStop: '#67c2ef', // just experiment with them
strokeColor: '#f2f4f8', // to see which ones work best for you
generateGradient: true
};
var target = document.getElementById('gauge1'); // your canvas element
var gauge = new Gauge(target).setOptions(opts); // create sexy gauge!
gauge.maxValue = 200; // set max gauge value
gauge.animationSpeed = 32; // set animation speed (32 is default value)
gauge.set(100); // set actual value
$.each(TicketResponse, function (index, car) {
gauge.set(car.CurrentTime); // set actual value
$('#lblAvgResponseTime').text(car.CurrentTime);
$('#lblAvgResponseTimePercent').text(car.diffPercent + ' %');
$("#iResponseTimeArrow").removeClass();
if (car.diffPercent < 0) {
//Closure time going up ==== BAD
$("#iResponseTimeArrow").addClass("fa fa-arrow-circle-o-up text-danger");
}
else {
//Closure time going down ===== GODD
$("#iResponseTimeArrow").addClass("fa fa-arrow-circle-o-down text-success");
}
});
},
failure: function (msg) {
$('#output').text(msg);
}
});
$.ajax({
type: "POST",
url: "CarService.asmx/GetClosureTime",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var TicketClosure = response.d;
var opts2 = {
lines: 12, // The number of lines to draw
angle: 0.05, // The length of each line
lineWidth: 0.44, // The line thickness
pointer: {
length: 0.75, // The radius of the inner circle
strokeWidth: 0.035, // The rotation offset
color: '#374767' // Fill color
},
limitMax: 'false', // If true, the pointer will not go past the end of the gauge
colorStart: '#fabb3d', // Colors
colorStop: '#fabb3d', // just experiment with them
strokeColor: '#f2f4f8', // to see which ones work best for you
generateGradient: true
};
var target = document.getElementById('gauge2'); // your canvas element
var gauge = new Gauge(target).setOptions(opts2); // create sexy gauge!
gauge.maxValue = 200; // set max gauge value
gauge.animationSpeed = 32; // set animation speed (32 is default value)
$.each(TicketClosure, function (index, car) {
gauge.set(car.CurrentTime); // set actual value
$('#lblAvgCloseTime').text(car.CurrentTime);
$('#lblAvgCloseTimePercent').text(car.diffPercent + ' %');
$("#iClosureTimeArrow").removeClass();
if (car.diffPercent < 0)
{
//Closure time going up ==== BAD
$("#iClosureTimeArrow").addClass("fa fa-arrow-circle-o-up text-danger");
}
else
{
//Closure time going down ===== GODD
$("#iClosureTimeArrow").addClass("fa fa-arrow-circle-o-down text-success");
}
});
},
failure: function (msg) {
$('#output').text(msg);
}
});
}
答案 0 :(得分:1)
您可以使用javascript setInterval()
功能:
setInterval(function() {
updateGauges();
}, 30000);
(30000毫秒= 5分钟)