尝试在 wordpress htaccess 文件中添加代码
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
并在 wordpress 中添加以下操作
/**
* Use * for origin
*/
add_action( 'rest_api_init', function() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', function( $value ) {
header( 'Access-Control-Allow-Origin: *' );
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
header( 'Access-Control-Allow-Credentials: true' );
return $value;
});
}, 15 );
或者只是在 wp-content/plugins/json-api/singletons/api.php 中添加以下内容
<? header("Access-Control-Allow-Origin: *"); ?>