Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top