【发布时间】:2021-10-27 19:12:23
【问题描述】:
我在 codepen 中有这段代码,它可以正常工作,但是如果我将此代码作为插件安装在 wordpress 网站上,它会在下面显示此错误。
从“https://vative.us15.list-manage.com/subscribe/post”访问 XMLHttpRequest(重定向自“http://vative.us15.list-manage.com/subscribe/post”)源“http://localhost:8888”已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。
我的代码笔在这里。
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();
}
});
有没有办法解决这个问题?请帮忙。
【问题讨论】:
标签: javascript ajax xmlhttprequest same-origin-policy