Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

anyone who solve "Response to preflight request doesn't pass access control" issue?

Ajay Kere June 4, 2018

Below is my javascript/ajax code

<html>
<body>

    Test <button onclick="testJira();">Click</button>
    <script>
    var username = "xxxxxxxxxxx";
    var password = "xxxxxxx";
     function make_base_auth(user, password) {
        var tok = user + ':' + password;
        var hash = btoa(tok);
        return "Basic " + hash;
    }
        function testJira() {
            
            $.ajax({
                type: "GET",
                crossDomain: true,
                dataType: "json",
                url: "https://xxxx.atlassian.net/rest/api/2/project",
                headers: {
                    'Content-Type' : 'application/json',
                    'Authorization' : 'Basic',
                    'X-Atlassian-Token': 'no-check',
                    'Access-Control-Allow-Origin' : '*'
                },
                beforeSend: function (xhr) {
                        xhr.setRequestHeader('Authorization', make_base_auth(username, password));
                    },
                success: function(result) {
                  alert('success:::::'+JSON.stringify(result));
                },
                error: function(error) {
                  alert('error:::::'+JSON.stringify(error));
                }
            });
        }
    </script>
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</body>
</html>

0 answers

Suggest an answer

Log in or Sign up to answer