在这段代码我想当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