我想在基本上關閉或啓動服務器的JQuery中運行一個函數。我到目前爲止的代碼是這樣的 -運行代碼之前的JQuery SetTimeout
$(".stopServer").click(function(){
$.post("controller.php",{stop: 'true', server: this.name});
$('#test'+this.name).load('controller.php?status=true&server='+this.name);
});
顯然,問題就停止服務器不錯,但它更新狀態DIV(「#測試」 + this.name)直線距離。這是不好的,因爲服務器需要一段時間才能關閉。我一直試圖讓SetTimeout工作,但無法弄清楚...任何幫助將不勝感激。
感謝球員,你是最好的:)
UPDATE:
完整的功能如下:
$(document).ready(function() {
$(".startServer").click(function(){
$.post("controller.php",{server: this.name});
setTimeout("showStatus('"+this.name+"')", 3000);
});
$(".stopServer").click(function(){
$.post("controller.php",{stop: 'true', server: this.name});
setTimeout("showStatus('"+this.name+"')", 3000);
});
function showStatus(name) {
alert(name);
$('#test'+name).load('controller.php?status=true&server='+name);
}
});
UPDATE
放棄它的想法,而不是相反,狀態每秒調查一次。
var refreshId = setInterval(function()
{
$('.status').each(function() {
var $name = $(this).attr('name');
$(this).load("controller.php?status=true&server=" + $name);
});
}, 1000);
我放棄了,我只是每秒調查一次狀態。 – Steve
@Steve - cool;如果你決定改變主意,那麼這裏是演示!祝你好運! – f0x
不管我想要什麼,所以我會給你選擇的答案:)感謝哥們:) – Steve