开发者

Cross Origin Resource Sharing

Hello I've been doing some reading on "CORS".

I think I understand the concept. However I'm having some difficulty performing a cross domain POST request.

I've set up two test sites on my local IIS.

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

Currently, the following code works:

<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>

However, as soon as I change the type from "GET" to "POST", I receive a 405 Method Not Allowed, error.

I'm hosting the test sites in 开发者_开发技巧IIS7.5. I've added the following HTTP Response Headers to the site hosted at http://localhost/CORSServer

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

I may be misunderstanding the sources I've read, I'm assuming that Cross Domain POSTing is available with CORS?

Can anyone see what I'm doing wrong, or have I misunderstood something?

Cheers,

James


It may be this : http://support.microsoft.com/kb/942051/en-us

Resolution 2

Instead of making the HTTP request to a static HTML page, make the HTTP request by sending the POST method to an Active Server Pages (ASP) page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜