问题是,当有一条新消息时,Chrome会用相同的值提醒5-8次,而不是只提醒一次。相比之下,这些代码在FF上工作得很好,它只会发出一次警报。如何修复代码以支持Chrome?HTML:
setInterval(function() {
$.get('/restaurant/get_msg_notification',{},function(data){
alert(data)
})
}, 1000)查看:
def get_msg_notification(request):
while True:
# check is there any new messages ?
msg = Message.objects.filter(receiver = user, notify = False)
if( len(msg)==0 and patient<5):
time.sleep(5)
patient+=1
else:
break
if( len(msg) > 0):
data = serializers.serialize('json', msg)
msg.update(notify = True)
return HttpResponse(data, mimetype="application/json")
else:
return HttpResponse("")发布于 2013-07-24 14:27:39
实际上,Firefox似乎才是不能正常工作的那个。请尝试以下代码:
def get_msg_notification(request):
while True:
# check is there any new messages ?
msg = Message.objects.filter(receiver = user, notify = False)
if(patient < 5):
time.sleep(5)
patient+=1
else:
if (len(msg) != 0):
msg.update(notify = True)
break
data = serializers.serialize('json', msg)
return HttpResponse(data, mimetype="application/json")https://stackoverflow.com/questions/17826544
复制相似问题