Avatar of Dinesh Bali
Dinesh Bali
 asked on

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,
* Cross-origin resource sharing (CORS)jQueryAJAX

Avatar of undefined
Last Comment
Dinesh Bali

8/22/2022 - Mon
David Favor

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.
Dinesh Bali

ASKER
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
ASKER CERTIFIED SOLUTION
Dinesh Bali

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck