2 minute read

While working on the launcher for some new enterprise build management stuff, I ran into a situation I hadn’t seen before. The core javascript that launched the process was working as expected in IE, but was failing + throwing a very scary looking Status Code 0 in Chrome.

Setting aside for a moment the amusement I felt by IE ‘working’ while Chrome failed, I dug into root causes behind a Status Code 0. Clearly, this isn’t a standard response code from the browser. While I initially thought the issue was timing-related (webkit’s javascript parser is faster), using alerts + setTimeouts didn’t shed any real light on why I was seeing this in Chrome.

I did figure it out & resolve it after about 10 minutes. The launcher has a form in which the user makes a couple selections to set the context for the work that is to be performed, and the form’s submission triggers a javascript function called getContext() that, if happy, would then fire off the actual worker asynchronously (ajax).

That form’s button was firing the form immediately rather than waiting for the results of the check(s). Adding a return false; to the button’s setup fixed it. Here’s how:


Why does this matter?

The moment the form’s do stuff! button is clicked, the form is submitted.  This means that the form was submitted at the same time the function was called, generating a response to the browser – the Status Code 0 – before the function could process anything. By setting return false; on the function call, the form submission is cancelled in the browser but the function call continues to process the request.