I have this code in codepen and it works properly however if I installed this code on a wordpress site as a plugin, it says this error below.
Access to XMLHttpRequest at 'https://vative.us15.list-manage.com/subscribe/post' (redirected from 'http://vative.us15.list-manage.com/subscribe/post') from origin 'http://localhost:8888' 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.
My codepen is here.
https://codepen.io/gegejosper/pen/powzGQJ?editors=1011
$.ajax({
type: "post",
url: "https://vative.us15.list-manage.com/subscribe/post",
dataType: "json",
data: data_val,
success: function(data) {
$(".optin-form").hide();
$(".optin-success").show();
},
//expected to be error in result.
error: function(data){
$(".optin-form").hide();
$(".optin-success").show();
}
});
Is there a way to fix this issue? Please help.