跨源资源共享

时间:2010-11-10 12:40:07

标签: jquery ajax iis cors

您好我一直在阅读“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>

但是,只要我将类型 “GET” 更改为 “POST” ,我收到405方法不允许,错误。

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

托管的站点
Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Methods: POST
Access-Control-Allow-Credentials: true

我可能误解了我读过的消息来源,我假设Cross Domain POSTing可用于CORS?

任何人都可以看到我做错了什么,或者我误解了什么?

干杯,

詹姆斯

1 个答案:

答案 0 :(得分:0)

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

  

决议2

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

相关问题