当 POST、JSON 数据到 Bitnami Redmine 时没有 'Access-Control-Allow-Origin' 错误

No 'Access-Control-Allow-Origin' Error when POST, JSON data to Bitnami Redmine

我正在尝试构建一个休息客户端 POST 数据到 Redmine API。我认为我无法更改 Redmine(服务器端)API 上的任何内容。授予访问权限。我已经在本地安装了 Redmine bitnami 堆栈(Redmine -> localhost/redmine)。 客户端文件位于 localhost:8080

    $(document).ready(function(){
        $("#submit").on('click', function(){
            // send ajax
            $.ajax({
                url: 'http://localhost/redmine/projects.json', 
                type : "post", 
                crossDomain: true,
                dataType : 'json',
                headers: { 'X-Redmine-API-Key': 'admin' }, 
                data : JSON.stringify({
                          "project": {
                            "name": "MANOJ",
                            "identifier": "MANOJ-perera",
                             "description": "This is a des"
    
  }
}), 
                success : function(result) {
                  
                    alert("Sucess");
                    console.log(result);
                },
                error: function(xhr, resp, text) {
                    console.log(xhr, resp, text);
                }
            })
        });
    });

我收到以下错误。

XMLHttpRequest cannot load http://localhost/redmine/projects/11n. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 404.

我该如何解决这个问题。请帮忙。

通过将两台主机都带到一个公共平台而不更改服务器端的任何内容来解决。 将 localhost:8080 中的所有数据复制到本地主机。在我的例子中,Redmine bitnami 堆栈在本地主机中,我开发的 Web 应用程序在 localhost:8080 中,将所有 webapp 文件带到 C:\Bitnami\redmine\apache2\htdocs\ 并解决了。