在這段代碼我想當div與.ch1類改變背景answer_box_small_orange.png其他底部js行代碼不運行,沒有ajax請求發送,直到3秒,我用延遲不運行其他代碼行
window.setTimeout(function() {}, 3000)
但它不正確地在這裏首先我要求的工作
,並得到數據,這是確定
$.ajax({
type:'post',
url:'http://207.154.251.233:8039/app.php/question/get',
data:JSON.stringify({apikey:'jwebdpqodp9fgkwjebfkdpqihdqlwkndqp'}),
success:(function (response) {
var x = response;
$("#question").text(x.result.question);
$(".op1").text(x.result.options["1"]);
})
});
我插入Ajax代碼和一些其他代碼功能,因爲我要運行它每隔60秒
function myInterval() {
$(".ch1").css('background-image','url(image/answer_box_small.png)');
var clock;
$(document).ready(function() {
clock = new FlipClock($('.clock'), 60, {
clockFace: 'Counter',
autoStart: true,
countdown: true,
callbacks: {
stop: function() {
$('#loading').fadeIn('5000');
$.ajax({
type:'post',
url:'http://79.175.166.98/',
data:JSON.stringify({apikey:'jwebdpqodp9fgkwjebfkdpqihdqlwkndqp'}),
success:(function (response) {
$('#loading').fadeOut('slow');
var x = response;
$("#question").text(x.result.question);
$(".op1").text(x.result.options["1"]);
var answer = x.result.answer;
if(answer == 1){
$(".ch1").css('background-image','url(image/answer_box_small_orange.png)');
}
window.setTimeout(function() {}, 3000);
})
});
}
}
});
});
}
myInterval();
window.setInterval(function(){
myInterval();
}, 60000);
'setTimeout'不會阻止腳本,它只是安排稍後運行的函數。 – Barmar
@Barmar我怎麼能阻止腳本例如3 seconds.im困惑。我GOOGLE了它,沒有什麼有用的發現 – sepehr
你沒有找到任何東西,因爲它幾乎總是錯誤的JavaScript阻止頁面。 Javascript沒有這樣做。 – Barmar