I have a task to send the user's personal data with API. But I have to implement it with SOAP. Below in the code I am using simple jQuery + Ajax dispatch, But I am getting error
Access to XMLHttpRequest at 'https://send.data.to.api/' from origin 'https://website.url' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
If I understand correctly, the server side is blocking my host from which trying to send data and the server side should give access host. If not, how can the error be corrected?
jQuery(document).ready(function($){
$('#send-candidate-data').on('click', function(){
var personal_data = {
'refCode': ref_code,
'name': firstName,
'lastname': lastName,
'phone': phone,
'email': email,
'comment': comment,
'file': newFiles,
'gender': selectedGender
}
var soapApiUrl = 'https://send.data.to.api/' + ref_code + '?=' + job_portal;
var payload = '<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' +
'<soap:Body>' +
'<JobApplication xmlns="http://www.host.net/">' +
'<item>' +
'<RefCode>' + personal_data.refCode + '</RefCode>' +
'<SalutationGender>' + personal_data.gender +'</SalutationGender>' +
'<FirstName>' + personal_data.name +'</FirstName>' +
'<LastName>' + personal_data.lastname +'</LastName>' +
'<EmailAddress>' + personal_data.email +'</EmailAddress>' +
'<Phone>' + personal_data.phone + '</Phone>' +
'<ApplicantComments>' + personal_data.commet +'</ApplicantComments>' +
'</item>' +
'</JobApplication>' +
'</soap:Body>' +
'</soap:Envelope>';
var settings = {
"async": true,
"crossDomain": true,
"url": soapApiUrl,
"method": "POST",
"headers": {
'POST': '/services/website.asmx HTTP/1.1',
'Host': 'host.job.io',
'Content-Type': 'text/xml; charset=utf-8',
'Content-Length': 'length',
'SOAPAction': 'http://www.host.net/AboutJobApplication',
'Access-Control-Allow-Origin': 'https://website.url',
"cache-control": "no-cache"
},
"processData": false,
"data": payload,
}
$.ajax(settings).done(function(response) {
conosole.log(response);
});
})
});