0
我想要做一个类似于在服务器端使用ajax和Django的rapidshare中的倒计时器。阿贾克斯和Django的安全倒数计时器
我的AJAX调用如下:
function loadXMLDoc(url,cfunc){
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
function getFile(){
countdown(15);//just shows the counter
loadXMLDoc("getfiles",function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("dlzone").innerHTML=xmlhttp.responseText;
}
});
}
,并在服务器端我有一个测试功能:
def getfile(request):
sleep(15)
return HttpResponse("file")
按预期工作一切都只是它让我知道如果有一个更好的让服务器休眠15秒。如果我使用JavaScript做了所有的等待,那么操纵变量和绕过倒计时将非常容易。但是,让服务器等待并不像是最好的解决方案。有什么建议?
这绝对听起来像是一种更好的方法。所以,如果理解正确,我应该有一个函数来设置截止日期,另一个函数检查是否到期。谢谢 – kirbuchi 2010-12-07 04:37:37