1

I'm creating an API to connect with JIRA- TEMPO.

My request is working with the plugin in chrome "ARC" and its returning results. But When I send it via jQuery ajax its showing the 'Access-Control-Allow-Origin' header is present on the requested resource.

I have searched all of the solutions provided in StackOverflow it's not working.

jQuery(document).ready(function () {
              $('.test').on('click', function () {
                $.ajax({
                  method: 'GET',
                  type:  'Content-type',
                  dataType: 'application/json',
                  url: 'https://domain.atlassian.com/rest/tempo-timesheets/3/worklogs?dateFrom=YYYY-MM-DD&dateTo=YYYY-MM-DD',
                  beforeSend: function (xhr) {
                    xhr.setRequestHeader("Authorization", "Basic " + btoa('username:password'));
                    xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
                  }
                }).done(function (msg) {
                  console.log(msg);
                }).fail(function () {
                  console.log("error");
                });
              });
            });

Kindly help to solve this problem. Is there any way to achieve this in PHP?

Jagadeesh
  • 734
  • 6
  • 26

1 Answers1

0

Add this header into your script on https://domain.atlassian.com/rest/tempo-timesheets/3/worklogs?dateFrom=YYYY-MM-DD&dateTo=YYYY-MM-DD:

header("Access-Control-Allow-Origin: *"); // you can replace "*" by your domain name
Salim Ibrohimi
  • 1,351
  • 3
  • 17
  • 35