【问题标题】:Cross Origin Resource Sharing跨域资源共享
【发布时间】:2011-05-07 20:53:18
【问题描述】:

您好,我一直在阅读“CORS”。

我想我理解这个概念。但是,我在执行跨域 POST 请求时遇到了一些困难。

我在本地 IIS 上设置了两个测试站点。

http://localhost/CORSService/hello.html    
http://localhost:8000/CORSClient/index.html

目前,以下代码有效:

<html>
    <head>
        <title></title>
        <script src="jquery-1.4.3.js" type="text/javascript" language="javascript"></script>
    </head>
    <body>
        This is my Hello World: "<span id="helloSpan" style="color: red"></span>"
        <script>        
            $.ajax({
                url: "http://localhost/CORSServer/hello.html",
                type: "GET",
                data: {words: ["tes"]},
                dataType: "json",
                cache: false,
                contentType: "application/json",
                success: function(result)
                {
                    $("#helloSpan").html(result.words[0]);
                },
                error: function(a, b, c)
                {
                    $("#helloSpan").html(a + ' ------- ' + b + ' ------- ' + c);
                }
            });
        </script>
    </body>
</html>

但是,只要我将 type"GET" 更改为 "POST",我收到 405 Method Not Allowed,错误。

我在 IIS7.5 中托管测试站点。我已将以下 HTTP 响应标头添加到托管在 http://localhost/CORSServer 的站点中

Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Methods: POST
Access-Control-Allow-Credentials: true

我可能误解了我所阅读的资料,我假设跨域 POST 可用于 CORS?

谁能看到我做错了什么,或者我误解了什么?

干杯,

詹姆斯

【问题讨论】:

    标签: jquery ajax iis cors


    【解决方案1】:

    可能是这样的: http://support.microsoft.com/kb/942051/en-us

    决议 2

    而不是制作 对静态 HTML 页面的 HTTP 请求, 通过发送 HTTP 请求 POST 方法到 Active Server Pages (ASP) 页面。

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 2018-05-04
      • 2011-07-05
      • 2011-07-31
      • 2019-07-13
      • 2018-05-14
      • 1970-01-01
      • 2014-01-18
      • 2014-10-08
      相关资源
      最近更新 更多