I’m trying to use Ajax to POST a request to the new JSON API. The request works from the Companies House test page (which suggests that the Application key is correct) but is not working from an HTML page when served from the same domain as the Application JavaScript domain.
When I try the request below, I see the following error:
No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://ericernie.co.uk’ is therefore not allowed access. The response had HTTP status code 401.
$.ajax({
url: "https://api.companieshouse.gov.uk/search/companies?q=sandstone",
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic xxxxxxx");
},
type: 'GET',
dataType: 'text',
crossDomain: true,
async: false,
cache: false,
contentType: 'application/json',
processData: false,
success: function (data) {
alert(JSON.stringify(data));
},
error: function(){
alert("Cannot get data");
}
});
Any help gratefully received.
Thanks
Andy