题
您好,我一直在阅读“ 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>
但是,一旦我改变了 类型 从 “得到” 到 “邮政”, ,我收到不允许的405方法,错误。
我正在IIS7.5中托管测试站点。我已将以下HTTP响应标头添加到托管的网站 http://localhost/CORSServer
Access-Control-Allow-Origin: http://localhost:8000
Access-Control-Allow-Methods: POST
Access-Control-Allow-Credentials: true
我可能会误解我阅读的资源,我假设CORS可以使用跨域的发布?
谁能看到我在做错什么,或者我误解了某些东西?
干杯,
詹姆士
解决方案
可能是这样:http://support.microsoft.com/kb/942051/en-us
决议2
与其将HTTP请求发送到静态HTML页面,不如通过将POST方法发送到活动服务器页面(ASP)页面来制作HTTP请求。
不隶属于 StackOverflow