Verifying html form using ajax synchronous request -
tldr: can onreadystatechange
event emulated somehow else synchronous requests without freezing browser, not fired in firefox?
~~~~~
i have created web form needs verification , elements server before being submitted.
what now, 'onsubmit'
fire ajax request server, send form details, parse them server side, , return unique verification number , md5 hash form.
the way meant work form should receive reply , proceed submit form. must note actual form submission normal post
submission without ajax - form posted server outside control.
i suppose need synchronous ajax request - not asynchronous used for. point form should never submitted before getting reply, because fail, reply contains important fields server on other side for.
i tested chrome , seems work fine synchronous requests. request, , onreadystatechange
fire handler parse reply.
but firefox not fire onreadystatechange
event in synchronous requests. behavior there version 1.5 or something.
what people do, i've seen, run handler anyway @ point - because response received , in dom (responsetext), onreadystatechange
event doesnt fired.
but not work me: depending on over code run it, response may not available yet, parsing fail.
i've tried 2 solutions, both of them bad:
- use synchronous request, , put handler on while loop, waiting reply.
- use asynchronous request, , have while(myvariable); wait until reply gets there (myvariable reply server, after handling responsetext.
both of these of course cause firefox freeze quite time, javascript waits in while
loop. in end works fine, if anti-freeze protections of firefox don't kick in , script on page not responding.
what suggest? can while loop without freezing browsers? maybe polling thingie doesnt poll every millisecond while loop does, every 1 second lets say, script doesn't freeze?
if request synchronous, once send() call returns reply available. that's whole point of synchronous requests. why need sort of looping @ in case?
Comments
Post a Comment