Add support for CORS / XHR

This is ready to be looked over now.
On L239 the response is passed through JSON.parse, this does not happen here?

Also we should be detecting JSON support?