title: XMLHTTPRequest Status 0 In Unusual Circumstances
body: <p>I've been working on an AJAX script to perform some simple test manipulations via the Node.JS MongoDB driver. This script is causing me no end of headaches, for the following reasons:</p>
  
  <ol>
  <li><p>When I run the script natively in the node.js command prompt, it runs to completion, and performs all of the operations I intend it to. A full trace of its activity in Chrome's Node Inspector reveals that it does indeed perform as intended.</p></li>
  <li><p>Having debugged the script via Node Inspector, I then wrote a simple test page to call that script via AJAX. Despite taking care to use proper asynchronous callbacks, the script appears to hold up the server for an inordinate period of time, and returns with an HTTP status code of 0.</p></li>
  <li><p>Having searched Stack Overflow for similar issues, the threads I surveyed all issue the same message - that this is a CORS problem. BUT ... if this was a CORS problem, NONE of the other AJAX scripts in the same directory would work, and would presumably return the same HTTP status code of 0.</p></li>
  <li><p>Firing up a new, simpler test script to see if MongoDB connections are somehow interfering with my node.js server, this new script did NOT trigger an HTTP status code of 0, but instead returned as expected, with the HTTP status code of 200. This new test script resides in the same directory as the troublesome script, so it can't be a CORS issue.</p></li>
  <li><p>Likewise, experimentally calling other scripts in the same directory via AJAX yields the same result - all the other scripts return HTTP 200 as expected.</p></li>
  </ol>
  
  <p>So, why is this <strong>one</strong> script returning with an HTTP status of 0, while <strong>every</strong> other script in the <strong>same</strong> directory returns with an HTTP status of 200?</p>
  
  <p>At this point, no doubt people will ask me to show the code. However, there's a slight problem. The script in question is 749 lines long, and I suspect that [1] it'll be impossible to pinpoint the error without embedding the entire code file in this question, and [2] numerous individuals will berate me for doing so. The fact that the script runs without errors in Node Inspector also makes this puzzling. I <em>can</em> edit this question and include all of that code if asked, but given what I've stated above, I have no idea where to begin pinpointing the error in that code, so there's no way I can select parts of it that <em>might</em> be problematic, <strong>especially</strong> in the light of the fact that it runs to completion, without error, in Node Inspector via the node.js command prompt.</p>
  
  <p>Just in case this issue is platform specific, I'm running Node V8.11.3 LTS and MongoDB 4.0 on Windows 7 64-bit.</p>