javascript - Will an ajax request ever reach readyState 4 if a local firewall is blocking the URL requested? -
it's understanding local (or local network) firewall blocking url prevent ajax request url reaching readystate 4. correct?
yes will. example, @ code.
function readystatecallback () { jsprint(this.readystate); }; var oreq = new xmlhttprequest(); oreq.onreadystatechange = readystatecallback; oreq.open("get", "http://foobarbaz.nnn", true); oreq.send();
you can try on this fiddle. every request triggers ready state of 1 , 4, not ready states 2 or 3.
see xmlhttprequest mdn docs.
0 unsent open() has not been called yet. 1 opened send() has not been called yet. 2 headers_received send() has been called, , headers , status available. 3 loading downloading; responsetext holds partial data. 4 done operation complete.
to determine if request failed (such being blocked firewall), check this.status. request 200. request didn't receive response, 0.
the status attribute must return result of running these steps:
- if state unsent or opened, return 0 , terminate these steps.
- if error flag set, return 0 , terminate these steps.
- return http status code.
source: w3 xmlhttprequest::status
network errors described as,
dns errors, tls negotiation failure, or other type of network errors discusses onreadystatechange event fired in case of error. readystate 4.
a firewall either prohibit dns resolution or tls packets being sent.
Comments
Post a Comment