Access JIRA REST API with javascript, JQuery

I am trying to do a issue search by using jira rest api.
with basic authentication

I did try add this server to jira whitelist

		$.ajax({
			type: 'GET',
			url: jiraApiBaseUrl + 'project?expand=JIR',//'issue/' + 'JIR-197',
			dataType: 'json',
			//jsonp: 'jsonp-callback',
			timeout: issueTimeout,
			success: function(data) {
					console.log('200.  Returned status of ' + data.status);
			},
			error: function(xhr) {
				console.log('Request failed.  Returned status of ' + xhr.status);
			},
     beforeSend: function(xhr, settings) {
					xhr.setRequestHeader('Authorization',authCredentials);
					xhr.setRequestHeader('Content-Type', 'application/json');
					xhr.setRequestHeader("Access-Control-Allow-Origin", "https://abc.com");
					xhr.setRequestHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
			}
		});

		$.ajaxPrefilter( function( options, originalOptions, jqXHR ) {
	  options.crossDomain ={
	    crossDomain: true
	  };
	  options.xhrFields = {
	    withCredentials: true
	  };
	});
});

I have found the error below:
Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.

There are some posts which also talked the same problem, but looks like not work for me.

Hi, @QQQ.

I haven’t personally experienced the same problem, but that smells like a CORS problem. Kindly try this video tutorial on how to handle it and let’s see if this solves your problem.

Cheers!
Ian

If you are gonna hit the out of the box JIRA Rest APIs, then I would suggest some minor changes to JIRA configuration
See answer given by - Benjamin Rou

Or if you need to access multiple JIRA instance, then you can make a custom plugin which allows CORS. I am not sure, but maybe you can extend the current REST API and provide one additional method for OPTIONS. Or you could define new and just copy/paste the functional code.