【发布时间】: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?
谁能看到我做错了什么,或者我误解了什么?
干杯,
詹姆斯
【问题讨论】: