2010-11-10 155 views
1

你好我一直在讀「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://localhost/CORSServer

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

舉辦了以下HTTP響應頭到現場我可能誤解我讀到的資料,我假設跨域發佈可與CORS?

任何人都可以看到我做錯了什麼,或者我誤解了一些東西嗎?

乾杯,

詹姆斯

回答

0

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

分辨率2

代替把 HTTP請求到一個靜態的HTML頁面, 通過發送發送HTTP請求POST方法到活動服務器頁面 (ASP)頁面。

+0

乾杯隊友,這並沒有發生在我身上,非常感謝! – Zack 2010-11-11 10:58:55