0

I have this script to get field metadata for creating issues of JIRA REST API. Here's my request:

$.ajax({
                    url:"https://jira.nutanix.com/rest/api/2/issue/createmeta",
                    headers: { 'Access-Control-Allow-Origin': '*' },
                    headers: {'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS'},
                    headers: { 'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token' },
                    type: "GET",
                    success: function (result) {

                        console.log(result);
                    }

                });

When this was ran on chrome, I got the error:

XMLHttpRequest cannot load https://jira.nutanix.com/rest/api/2/issue/createmeta. response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

But, when I run the same script on firefox, I get no such errors. I have read about CORPS, and I think I understand it. But I don't understand why it works on firefox, but not on chrome. Is this a chrome thing that I am going to have to live with?

I have come across some extensions or changing chrome settings to disable CORS. But I think that is a work around only in my machine where I am developing. What about the end users? I can't expect them all to have the extension installed.

Any help is appreciated. Thank you :)

stick
  • 88
  • 3
  • 8

1 Answers1

0

Most of the modern browsers block ajax calls to cross servers. You need to enable CORS (Cross-Origin Resource Sharing) on the server if you have access to the server or you need to find some alternative for this.

You can refer to this post.

kk.
  • 3,747
  • 12
  • 36
  • 67