Has anyone successfully called an analytics API from JavaScript using jQuery?
I've been struggling with this issue for a few days now without any success. I attempted to use CORS, which resulted in an OPTIONS request being rejected with a 405 error. I also tried using jsonp, but it seems like server-side configuration is necessary based on what I've read.
Here's a simple sample code snippet that I've been working with:
$.ajax({
url: 'https://analytics.algolia.com/1/searches/test/popular',
method: 'GET',
beforeSend: (xhr) => {
xhr.setRequestHeader('X-Algolia-Application-Id', 'sample');
xhr.setRequestHeader('X-Algolia-API-Key', 'sample');
},
success: (response) => {
console.log(response);
}
});
I also experimented with setting crossOrigin to true and dataType to 'jsonp'.