Hsn_lin 发表于 2010-12-11 09:46:19

有懂ajax的吗,帮我弄个问题

我有一段检测URL是不是死链的代码
function check_link_url(counts) {
var tmp = "link" + counts;
if ($("#" + tmp).html() != null) {
$("msg_" + tmp).hide();
var url = $("#" + tmp).html();
ajax_check_site(url, tmp);
counts = counts + 1;
setTimeout("check_link_url(" + counts + ")", 800);
}
}
function ajax_check_site(url, tmp) {
$.ajax( {
type : "POST",
url : "/linksinfo/check_link_url",
data : "url=" + url,
dataType : "json",
success : function(msg) {
   if (msg.result == 1) {
    if (msg.timeout > 2) {
   $("#msg_" + tmp).show().html('<span style="color:red">√过慢</span>' + msg.timeout + "s");   
    } else {
   $("#msg_" + tmp).show().html("√   正常" + msg.timeout + "s");
    }
   
   } else {
    $("#msg_" + tmp).show().html("×");
   }
},
error : function() {
   $("#msg_" + tmp).show().html("×");
}
});
return true;
}

counts表示总连接数 从1开始
√ 表示URL可以访问
×表示URL不能访问
现在我想把×和√的总数给记下来
不知道怎么计数
求高手指点下

ionstar 发表于 2010-12-13 13:17:16

把要请求的URL全部放到一个数组里,然后迭代调用。然后再 success+=1;error+=1;

如果一个的调用就只能存数据库,或着存文件。
页: [1]
查看完整版本: 有懂ajax的吗,帮我弄个问题