Angular 2: EXCEPTION: Response with status: 0 for URL: null

廉价感情. 提交于 2019-11-29 09:12:25
giaco

It's probably a CORS issue.
Your Angular2 APP is hosted on another server than the API you're calling.

If you want to bypass this (only for test purposes), install this Chrome extension and add

Access-Control-Allow-Origin:

to your headers.
For real usage you should call the API from your server(Node, PHP, Python ...) (where the angular2 APP is hosted) and pass data to your angular2 APP.

As a side note, this also happens when the server is just offline.

I ended up here because I was wondering if there was an official meaning to status 0 and URL null.

We had some of those in our log. After a little digging it seems like they come whenever a ajax request is aborted after the browser started navigating to a new url.

I having similar issue when running Jesmine/Karma unit test. After checking long time,I came to know that this issue is because of some services are not mocked properly. When test case loaded service calls were aborted by the browser. Hence this error is coming.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!