krampstudio / aja.js

Ajax without XML : Asynchronous JavaScript and JavaScript/JSON(P)
http://krampstudio.github.io/aja.js/
MIT License
306 stars 45 forks source link

Supress error when the server return 200 and intentionally return no content #11

Closed phanect closed 9 years ago

phanect commented 9 years ago

On JSON access, if the server returns 200 and intentionally return no content, error is triggered. JSON.parse(res) tries to parse response content, but it is actually null (i.e. not JSON) and throws error.

phanect commented 9 years ago

First 2 commits are #10's. Plz merge after you merged #10.

phanect commented 9 years ago

And sorry again, but test is in progress. I don't know how to respond null by grunt-contrib-connect's middleware. Do you know how to solve this?

krampstudio commented 9 years ago

Hi, thank you for your contributions, it's really great that you help fixing aja.js errors of youth. I don't think you need to respond null because JSON.parse(null) returns null and does not trigger an Error, but if the value is undefined. You should just try with res.end();

krampstudio commented 9 years ago

And please, do not forget to add your details in the contributors fields of the package.json (if you're agree with that)

phanect commented 9 years ago

I don't think you need to respond null because JSON.parse(null) returns null and does not trigger an Error, but if the value is undefined.

Oh, then maybe empty string or something falsy is returned in my environment. Maybe if(res) works, but it is considerable what value should be returned by test server.