0

問題は、新しいメッセージがある場合、Chrome では 1 回だけアラートを出すのではなく、同じ値で 5 ~ 8 回アラートを出すことです。対照的に、これらのコードは FF でうまく機能し、1 回だけ警告します。コードを修正して 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("")
4

1 に答える 1

0

実は、うまく動かないのは 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")
于 2013-07-24T06:27:39.443 に答える