Ajax call to open the Kibana page


(Tushar Suvarna) #1

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
});


(Shaunak Kashyap) #2

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


(Tushar Suvarna) #3

Hi Sorry for my Late reply .

below is the images for the request and response


(Tushar Suvarna) #4

@shaunak


(Tushar Suvarna) #5

@shaunak

Chrome Developer tools previous was for Safari:


(Shaunak Kashyap) #6

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?


(Tushar Suvarna) #7

@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 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'


(Tushar Suvarna) #8

@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


(M Selman Sezgin) #9

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.


(Tushar Suvarna) #10

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


(M Selman Sezgin) #11

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


(system) #12

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