Hi!
I have a button on my form to get a company's details via the UK Government Company House API (registry of all companies in the UK). The script errors (error text copied from the Chrome console):
Access to XMLHttpRequest at 'https://api.company-information.service.gov.uk/company/03196209' from origin 'https://forms.plumsail.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I tested the script with a CORS proxy in the URL - it runs ok and returns the company details to the form. However, I don't want to use a CORS proxy in the live form for security concerns.
Is there another solution?
This is the script (without a CORS proxy):
$.ajax
({
type: "GET",
url: "https://api.company-information.service.gov.uk/company/" + fd.field('CoNum').value,
dataType: 'json',
async: false,
headers: {
"Authorization": "Basic xxxx"
},
success: function (response){
fd.field('CoName').value = response.company_name;
},
error: function(xhr){
alert(xhr.status + ": " + xhr.statusText);
}
});
Thanks!