Hi there. We're new to Klaviyo (migrating over from Mailchimp) and are creating a custom sign-up form via AJAX.
However, when doing so we are facing a CORS policy issue, with a console error of 'Access to XMLHttpRequest at 'https://a.klaviyo.com/api/v2/list/XXXX/subscribe' from origin 'https://devsite.local' 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.'
Is there any way around this, by adding accepted URLs for example to our Klaviyo account?
If not, any pointers as to the best AJAX based approach would be much appreciated.
Here is our current code:
$.ajax({
type: "POST",
url: "https://a.klaviyo.com/api/v2/list/{list}/subscribe",
data: JSON.stringify({
api_key: "{api-key}",
email: email,
}),
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
// Success
success: function (response) {
// Output result for debugging
console.log(response);
},
// Error
error: function (response) {
// Output result for debugging
console.log(response);
},
});
Many thanks