admin管理员组文章数量:1122832
I have an issue with CORS policy. The request to retrieve URL is being blocked. I tried everything (Access-Control-Allow-Origin: * in .htaccess, theme's function.php, theme's header and wp-config.php file as well) and nothing seems to work. It works perfectly on localhost though.
Here's my JS AJAX script:
$.ajax({
type: "POST",
url: Theme_Variables.ajax_url,
data: ({
action: 'myaction',
postID: postID,
price: price,
}),
success: function(response) {
response = response.slice(0, -1);
console.log(response);
$('.Link').prop('href', response);
//window.location = response;
},
error: function(errorThrown){
console.log( 'error' + JSON.stringify(errorThrown));
}
});
The error I get is: Access to XMLHttpRequest at '' (redirected from '.php') from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin.
Can anyone help? It would'nt be strange if it didn't work in localhost, but it does...
I have an issue with CORS policy. The request to retrieve URL is being blocked. I tried everything (Access-Control-Allow-Origin: * in .htaccess, theme's function.php, theme's header and wp-config.php file as well) and nothing seems to work. It works perfectly on localhost though.
Here's my JS AJAX script:
$.ajax({
type: "POST",
url: Theme_Variables.ajax_url,
data: ({
action: 'myaction',
postID: postID,
price: price,
}),
success: function(response) {
response = response.slice(0, -1);
console.log(response);
$('.Link').prop('href', response);
//window.location = response;
},
error: function(errorThrown){
console.log( 'error' + JSON.stringify(errorThrown));
}
});
The error I get is: Access to XMLHttpRequest at 'https://someotherurl.com' (redirected from 'https://myurl.com/wp-admin/admin-ajax.php') from origin 'https://myurl.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin.
Can anyone help? It would'nt be strange if it didn't work in localhost, but it does...
Share Improve this question edited May 29, 2024 at 21:13 Tony Djukic 2,2594 gold badges18 silver badges33 bronze badges asked May 17, 2024 at 12:25 Sam1501Sam1501 113 bronze badges1 Answer
Reset to default 1The problem was that the PHP AJAX function was redirecting to another page, which caused these issues. I decided to just generate a link instead of redirecting.
本文标签: AJAX request blocked by CORS policy
版权声明:本文标题:AJAX request blocked by CORS policy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305695a1932682.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论