Ajax call to open the Kibana page

Hi,

I am trying to make sample ajax call to the kibana server running on port 5601 on my local computer.
But I am getting an "Failed to load resource: Preflight response is not successful". I have not enabled any xpack or security packages.

I am trying to do achieve Authentication handshake between the Kibana and localserver with an AJAX call before rendering the data from the kibana.

for now a sample ajax call is giving me preflight error when I am calling from one local server with port 8080 to kibana server port 5601.

Can Anyone help me with this.

Sample Call
var ajaxSuccess = function (response) {
console.log("Success");
};

var ajaxError = function() {
	console.log("Error");
	
	
};

		$.ajax({
	  type: "POST",

// xhrFields: {
// withCredentials: true
// },
// data:loginData,
// contentType: "application/x-www-form-urlencoded",
// crossDomain: true,
// beforeSend : function(xhr) {
// xhr.setRequestHeader('Authorization' ,btoa("user" + ":" + "admin"));
// },
// headers: {
// 'Access-Control-Allow-Credentials':true,
// 'Access-Control-Allow-Origin': '*',
// 'Access-Control-Allow-Methods':'GET, POST, OPTIONS, PUT, PATCH, DELETE',
// 'Access-Control-Allow-Headers':'X-Requested-With,content-type,Authorization',
// 'Access-Control-Max-Age': '1728000'
// },
url :"http://localhost:5601",
dataType: "json",
// jsonpCallback: "ajaxSuccess",
success: ajaxSuccess,
error: ajaxError
});

Hi @Tushar_Suvarna,

Could you open your browser's developer tools console, networking tab? There should be an OPTIONS request in there. Could you copy/paste the details, specifically the request and response headers, of that request here?

Thanks,

Shaunak

Hi Sorry for my Late reply .

below is the images for the request and response

@shaunak

@shaunak

Chrome Developer tools previous was for Safari:

Hmm... looks like you're getting a 404 from the OPTIONS request. I see that the request is being made to http://localhost:5601 with the Access-Control-Request-Method header set to POST. Since http://localhost:5601 does not support POST requests, you are getting a 404 back.

I am trying to do achieve Authentication handshake between the Kibana and localserver with an AJAX call before rendering the data from the kibana.

Could you elaborate on this a bit more? You mentioned that you are not using xpack or any security packages. Does your Kibana instance require authentication some other way?

@shaunak

As of now I am not using any authentication for kibana,just wanted to hit the Kibana and get an success reponse. I am planning to use the authentication once kibana is able to handle the ajax calls.

Also using curl POST command I am able to achieve the success call.

Since http://localhost:5601 does not support POST requests, you are getting a 404 back.

I have seen some discussions > Authenticating to iframe-embedded Kibana dashboard - #7 by weltenwort on the POST commands. Can you please elaborate why Kibana does not work on POST calls and is there some other calls which can be passed to Kibana like 'GET/PUT'

@shaunak

Thanks for all the help I figured out what you meant and found a better way to meet my requirement and its working.

Regards
Tushar

Hi there,
What was the "better way"? Can you tell me please?
I'm trying to use kibana visual, inside my web app but i need to authenticate with ajax call. Same preflight error happens.

Hi,

There is no way to do so through Ajax call, because when an Ajax call is made for Cross Domain the method type "OPTIONS" is passed to the server and Kibana does not have a way to handle OPTIONS call in there product built code. They gave an option of using proxy server where you can authenticate and pass the request forward, but that still did not work for me as iframe cannot be shared in CROSS Domain.

Hope that suffice what you wanted.

Regards
Tushar

Thanks, answer is very helpful for me, i will look for a non cloud way.
Regards.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.