We help IT Professionals succeed at work.

CORS error - Even CORS is allowed for the domain - status 200 in network tab

Hi,

I am getting CORS error in my website. Even though I am getting status 200 in network tab as CORS was allowed for the domain.

jquery-2.1.4.min.js:4 Access to XMLHttpRequest at 'https://authuat.mysite.com/api/users' from origin 'http://etgsit.hrt.uyetr.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

In Nework tab, I am getting status 200 for the API https://authuat.mysite.com/api/users as CORS was allowed for domain
http://etgsit.hrt.uyetr.com

Code as below:
$.ajax({
        url: 'https://authuat.mysite.com/api/users',
        type: 'GET',
        xhrFields: { withCredentials: true },
        accept: 'application/json',
        async: false
    }).done(function (data) {

        console.log(data);

    })
        .fail(function (jqXHR, textStatus, error) {

            console.log('falied');
        });

Open in new window


Please advise on this.

Regards,
Comment
Watch Question

David FavorFractional CTO
Distinguished Expert 2019

Commented:
Tip: http://etgsit.hrt.uyetr.com fails to resolve in DNS, so you'll have to fix this first or use an /etc/hosts entry, which will likely fail in many subtle ways for an API system.

Author

Commented:
Hi,

URL is resolving that is the reason it is giving 200 status in network tab.
It is working now. It was not working because of cookie policy.
 I have updated my config to access in https only and I was accessing site in http.

Its working now . Thanks
details above