rezoner / playground

Playground.js is a framework for your javascript based games. It gives you out-of-box access to essentials like mouse, keyboard, sound and well designed architecture that you can expand to your needs.
MIT License
466 stars 50 forks source link

XMLHttpRequest returning a Status Code of 0 in nw.js #6

Closed RoryDuncan closed 9 years ago

RoryDuncan commented 9 years ago

My app wont load because of the above problem, when running nw.js v0.12.0 and PlaygroundJS r2.

I just tested in an empty playground, in case it was an oddity with my app.

example

I tracked it down and it seems to be from from the status code being incorrect, as the responseText is as expected, but the Status Code is tripping this conditional in the Loader.loadData function

I looked up a bit about the status code, and ran across a Stack Overflow Discussion about it.

Despite the stack overflow discussion suggesting checking the environment, a temporary fix could be:

if (xhr.status !== 200 && xhr.status !== 0) {
  return app.loader.error(entry.url);
}

Though that works, would we want some form of environment detection to decide to use fs when the environment is nodewebkit or to use XMLHttp when in a browser, as discussed in the SO?

rezoner commented 9 years ago

Thanks for noticing that and such a deep investigation.

Your "temporary" solution seems to be a widely accepted one:

https://github.com/jquery/jquery/blob/master/src/ajax/xhr.js#L17

I will use it for now - as an abstraction between xhr and fs has to be well thought and communicated to the user and I have to consider many things - including that using require('fs') possibly gets in the way of browserify .

rezoner commented 9 years ago

Pushed the update. Please let me know if it works.

https://github.com/rezoner/playground/tree/master/build