产品要写一个类似检测的东西
有四块内容检测,要发四个AJAX。
我想到的$,when
但是用这个的话,后面三个done时间是立马执行的。
我就写了一个settimeout
但是里面有一个依次打对号的我就写了一个setInterval
但是这个时间老是对不上。
发现写法很有问题 有没有什么好点的写法 或者指出我的错误。
$('.txturl button').click(function() {
var count = 0
$.when($.ajax({
type: "get",
url: "http://www.webossgoo3.com/google/CheckContent",
async: true,
success: function(data) {
var pardata = JSON.parse(data)
$('.gdt').addClass('layui-anim layui-anim-rotate layui-anim-loop');
$('.coun-jc').hide();
$('.txt-bet li').removeClass('active')
$('.txtnum section span.load-jc').css('display', 'table-cell');
if(pardata.title) {
$('.cont2 i').html('ဆ')
$('.cont2 i').css('color', 'red')
for(j in pardata.title) {
$('.contentul ul').eq(0).append(
"<li>" + j + ":" + pardata.title[j] + "</li>"
)
}
};
for(k in pardata.keywords) {
$('.contentul ul').eq(1).append(
"<li>" + k + ":" + pardata.keywords[k] + "</li>"
)
}
if(!pardata.original) {
$('.cont1 i').html('ဆ');
$('.cont1 i').css('color', 'red')
}
var i = 0;
setInterval(function() {
if(i <= $('.basetxt table i').size() - 1 ) {
$('.basetxt table i').eq(i).show()
i++
} else {
$('.txt-bet li').eq(0).addClass('active')
return false
}
}, 500)
},
error: function() {
layer.msg('检测失败1')
}
})).done(function() {
setTimeout(function () {
$.ajax({
type: "get",
url: "http://www.webossgoo3.com/google/checkSearch",
async: true,
success: function(data) {
var pardata = JSON.parse(data)
if (pardata.google) {
$('.cont3 i').html('ဆ')
$('.cont3 i').css('color', 'red')
}
if (pardata.bing) {
$('.cont4 i').html('ဆ')
$('.cont4 i').css('color', 'red')
}
if (pardata.yahoo) {
$('.cont5 i').html('ဆ')
$('.cont5 i').css('color', 'red')
}
if (pardata.title_top1) {
$('.cont6 i').html('ဆ')
$('.cont7 i').css('color', 'red')
}
var a = 0;
setInterval(function() {
if(a <= $('.seartxt table i').length - 1) {
$('.seartxt table i').eq(a).show()
a++
} else {
$('.txt-bet li').eq(1).addClass('active')
return false
}
}, 500)
},
error: function() {
layer.msg('检测失败2')
}
})
})
}).done(function() {
setTimeout(function () {
$.ajax({
type: "get",
url: "http://www.webossgoo3.com/google/CheckSearch",
async: true,
success: function(data) {
var pardata = JSON.parse(data)
var i = 0;
setInterval(function() {
if(i <= $('.seotxt table i').length - 1) {
$('.seotxt table i').eq(i).show()
i++
} else {
$('.txt-bet li').eq(2).addClass('active')
return false
}
}, 500)
},
error: function() {
layer.msg('检测失败3')
}
})
},500 * ($('.seartxt table i').length) )
}).done(function() {
setTimeout(function () {
$.ajax({
type: "get",
url: "http://www.webossgoo3.com/google/CheckContent",
async: true,
success: function(data) {
var pardata = JSON.parse(data)
var i = 0;
setInterval(function() {
if(i <= $('.basetxt table i').length - 1) {
$('.opttxt table i').eq(i).show()
i++
} else {
$('.txt-bet li').eq(3).addClass('active')
$('.gdt').removeClass('layui-anim layui-anim-rotate layui-anim-loop');
$('.coun-jc').show()
$('.coun-jc').text('88')
$('.txtnum section span.load-jc').css('display', 'none');
return false
}
}, 500)
},
error: function() {
layer.msg('检测失败4')
}
})
},500 * ($('.seotxt table i').length) + 500 * ($('.seartxt table i').length) )
})
})