In JavaScript I get JSON data. The service sends me back JSON data in a file (HTTP Header – file), a second service sends me back data as text in browser (HTTP Header type – text/html).
I need to parse this data in JavaScript (ExtJS).
It is different to Javascript, getting JSON as text/html and as file?
I know that with text/html – all works fine, but will it work with other HTTP Header type (that retrieves file that contains JSON)?
Thanks
If your response content-type is
text/htmlyou should be fine, as long as you parse the response with something likeJSON.parse(see json2.js for older browsers that don’t have this natively) it should be fine.In fact, if you’re loading your response from an iframe – IE will prompt you to download a file if your response is
application/json. This should only be an issue if you’re attempting a file upload without refreshing the page though.To be honest I’ve never tried with other header types. I would imagine
text/plaincould work, however you may run into the IE iframe download issue above.My recommendation would be to use
application/jsonif you can, however failing thistext/htmlshould suffice