2014-09-02 58 views
-1

我遇到一個奇怪的問題,並且認爲它是特權,但不知道在哪裏可以找到問題?當我點擊一個按鈕時,我創建了一個簡單的html測試頁面來對我的web服務器執行ajax調用。Ajax Call Windows8權限

jQuery.support.cors = true; 
    var pageUrl = 'http://webservice.svn/WebService1.asmx'; 

    $.ajax({ 
     type: "POST", 
     url: pageUrl + "/Helloworld", 
     data: '{}', 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (response) { 
      alert(response.d); 
     }, 
     error: function (response) { 
      alert(response.status + " " + response.statusText); 
     } 
    }); 

運行與URI ADRESS http://mobile.svn/test.html html頁面 - 我得到錯誤0,但運行的URI - C:\手機\ test.html的它返回的Hello World。所以,我可以看到它是通過IIS 運行時,我運行Windows 8.1 感謝

更新發生故障的AJAX因爲跨域資源共享(CORS)的POST請求 enter image description here

+1

錯誤0通常表示CORS錯誤,請求不能出於某種原因做。你在瀏覽器的控制檯中收到什麼錯誤信息?這應該給你更具體的東西。 – hotforfeature 2014-09-02 13:35:49

+0

感謝您的快速響應,所以它似乎是某種CORS錯誤,但如果我將support.cors設置爲false,則會出現無傳輸錯誤 – 2014-09-02 13:57:50

回答

0

感謝abmichelle!你指引我走向正確的方向。 我的web服務沒有在webconfig customHeaders ... :-)

<customHeaders> 
    <add name="Access-Control-Allow-Origin" value="*" /> 
    <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE"/> 
    <add name="Access-Control-Allow-Headers" value="Content-Type, Accept"/> 
</customHeaders>