python - Dajaxice callback function called twice -
i'm using django-dajaxice-ng package (django-dajaxice fork django 1.5 , above, since use django 1.5.4), , have strange issue.
callback function called twice or more.
simple usage:
... {% load dajaxice_templatetags %} ... {% dajaxice_js_import %} <script> function update_chat(data) { messages = eval(data.messages); howmany=messages.length; if (howmany>0) console.log('called'); (i=0;i<howmany;i++) { m=messages[i]; console.log(m.msg,m.sent); }; } setinterval(function() { dajaxice.myapp.receivechat(update_chat,{'userid': {{otheruser.id}} }); },2000); </script> and in myapp/ajax.py:
def receivechat(request,userid): # find new messages userid , mark them read. return json.dumps({'messages':serialized_messages}) here's console log:
called "message" "16:09:28" called "message" "16:09:28" as can see, (very often, actually) update_chat triggered 2 or 3 times.
i'm 100% sure that:
- the ajax function receivechat called once
- the message shown twice stored once.
i define serialized_messages = json.dumps(messages), being messages list of dicts.
result this:
'[{"msg": "message", "sent": "16:09:28"}]' in case there's 1 message, works more one.
i had double serialization (the other one's in return) because apparently dajaxice accept dict admitted return values.
anyone got behavior? clue?
edit i'm using neo4django uses neo4j-rest-client, have .save() on model, , notice save got problem, maybe because of http request?
edit 2 it's not dajaxice issue, switching ajax $.get() gives same results, can't figure out. seems not browsers doing it, sure chrome does.
Comments
Post a Comment