HTTP interceptor getting status 0 on failed request using Angular 4

ぃ、小莉子 提交于 2019-12-01 01:30:28

If You are using CORS you should check "Access-Control-Allow-Origin" in your server configuration.

I Solved this on my nginx server adding:

add_header "Access-Control-Allow-Origin" * always;

I missed the "always" parameter which caused me the same problem as yours.

You should pay attention to the value of the header "*" in my example.

The value must contain the list of allowed origins.

Rameez Rami

I found out what was causing the issue.. Its a server side issue. You need to set the CORS middleware first then the remaining API middlewares.

Please note i am working with Laravel 5.6 + Angular 5

Wrong Code

'api' => [
            'throttle:60,1',
            'bindings',
            \Barryvdh\Cors\HandleCors::class,
        ],

Currect Code

'api' => [
            \Barryvdh\Cors\HandleCors::class,
            'throttle:60,1',
            'bindings'
        ],
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!