Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this XMLHttpRequest POST fail to even connect to the server?
    text
    copied!<p>I have an XMLHttpRequest opened with the POST method, to a URL that I know exists because I've just done a GET on it. However, the send() call on the XHR doesn't actually open any connection to the server or send any data -- I've verified this with WireShark. Instead, it just fails the request, calls the onreadystatechange event handler, setting status to 0 (meaning, according to the spec, that the "error flag" is set).</p> <p>But... there's no way for me to inspect WHAT is going wrong. I've tried this in FireBug, and the headers and body look OK; there is no response body or response headers. The line in the console output is a POST /url (x) where the (x) is a red circle with an X in it. No error reason is visible anywhere. That same line is not in the NET panel at all. This is probably a clue, but I don't know of what.</p> <pre><code>function save_edits(url, txt, cb) { var xhr = new XMLHttpRequest(); console.log("'POST' " + url); xhr.open('POST', url, true); xhr.onreadystatechange = function(ev) { if (xhr.readyState == 4) { console.log('post complete status:' + xhr.status); cb(); } } xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); var text = "&amp;" + edit_what + "=" + escape(txt.replace(/\r/g, '\n')); try { xhr.send(text); } catch (e) { console.log('send() error: ' + e.toString()); } </code></pre> <p>This outputs in the FireBug console:</p> <ol> <li>'POST' <a href="http://mydomain.com/srv.json.section-xna.latest" rel="nofollow">http://mydomain.com/srv.json.section-xna.latest</a></li> <li>POST <a href="http://mydomain.com/srv.json.section-xna.latest" rel="nofollow">http://mydomain.com/srv.json.section-xna.latest</a> source.js (line 70)</li> <li>post complete status:0</li> </ol> <p>Line 1) is my console log statement.</p> <p>Line 2) is the POST XHR request, which is red, with the circle-X showing failure.</p> <p>Line 3) is the console log statement from the onreadystatechange handler.</p> <p>There is no exception raised (I put that check in there just for paranoia) -- even if I make the open() be synchronous instead of asynchronous.</p> <p>Again, this is not a server-side problem, because the request doesn't even make it onto the wire, and I don't know how to figure out why that is.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload