CORS Problem - AJAX

Hi,

I wanna send data with a webflow form to an API using the following script:

 var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://api.recruitee.com/c/werkenbijvanstraatenpost/careers/offers/scooter-postbezorger-in-heel-nederland/candidates",
  "method": "POST",
  "headers": {
    "Content-Type": "application/json",
    "Cache-Control": "no-cache",
  },
  "processData": false,
  "data": "{\r\n  \"candidate\": {\r\n    \"name\": \"John Smith\",\r\n    \"email\": \"john.smith@example.com\",\r\n    \"phone\": \"987654321\",\r\n    \"cover_letter\": \"Example cover letter\",\r\n    \"remote_photo_url\": \"https://site.example.com/images/myimage.jpeg\",\r\n    \"remote_cv_url\": \"https://site.example.com/resumes/myresume.pdf\",\r\n    \"open_question_answers_attributes\": [\r\n      {\r\n        \"open_question_id\": 5,\r\n        \"content\": \"Yes\"\r\n      },\r\n      {\r\n        \"open_question_id\": 8,\r\n        \"content\": \"Responsibility\"\r\n      },\r\n      {\r\n        \"open_question_id\": 9,\r\n        \"content\": \"Blue\"\r\n      },\r\n      {\r\n        \"open_question_id\": 10,\r\n        \"content\": \"Pizza, Hamburger\"\r\n      }\r\n     ]\r\n  }\r\n}"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

Is there a way to avoid to CORS ptoblem so i can use a form on webflow that send data to the following API?

Thanks in advance!

Kind regards,
Edwin

Hi @EdwinN1337, at the moment the ability to setup CORS is not supported natively. You might try to change the script url to originate from a subdomain on your site, i.e. code.yourdomain.com, where “code” is a cname record setup to point to your code server.

The url in that case would be something like:

https://code.yoursite.com/...

I hope this helps

You can use Zapier to make the POST to the server. I personally now use Built.io Flow (enterprise) to make calls from Webflow.

Thanks for the response.

Zapier still not working for me, not sure what i’m doing wrong (error: wrong datarequest).

But im working on it!

You might try to change the script url to originate from a subdomain on your site, i.e. code.yourdomain.com , where “code” is a cname record setup to point to your code server.

@cyberdave, could you elaborate a bit on this, or perhaps share any resources that explain this in more detail?

I’m having CORS issues trying to import postscribe. I think your solution sounds promising but I’m not sure I understand it fully.

The cname record would essentially be a proxy for the actual javascript library, right? What kind cname record?

Hi @Greg_Condit, thanks for your reply, CORS would need to be enabled at Postscribe to handle cross domain requests, otherwise you can try to setup a cname record for a subdomain of your main domain and point that at the server hosting the postscribe script.

Basically, the postscribe code will not load unless the code originates on the same domain as the page where the script is run.

Setting up a CNAME like “code.yourdomain.com” that points to where the postscribe script is hosted will allow you to use that for pages hosted under yourdomain.com (although you have to test, custom code is not guaranteed to run"

jQuery is loaded automatically for every Webflow site, so in most cases it is not necessary to load it a second time. I hope this helps.