2013-07-01 16 views
0

我有2臺服務器安裝了不同版本的.NET。服務器1具有.NET 1.1,服務器2具有.NET 3.5。將HTML/Javascript文件移動到不同的服務器會使其無法正常工作

我有.net 3.5服務器,以下工作正常的web服務:

function selectedDateTime(strDate, strHours, strMinutes) { 

    $.ajax({ 
     url: 'webservice.asmx/GetCount', 
     type: 'POST', 
     data: '{strMeetingDate: "' + strDate + ' ' + strHours + ':' + strMinutes + ':00"}', 
     contentType: 'application/json; charset=utf-8', 
     dataType: 'jsonp', 
     success: function(department) { 
      console.log("success: " + department.d); 
     }, 
     error: function(xhr, status, error) { 
      console.log("status message: " + status); 
      console.log("error message: " + error); 
      console.log("xhr message: " + xhr.responseText); 

     } 
    }); 

} 

$("#btnTest").click(function(event) { 
    selectedDateTime("01/07/2013", "13", "00"); 
}); 

我想使用相同的腳本老.NET 1.1的服務器上也是如此,但無法移動webservice到舊服務器,因爲它是使用.NET 3.5編寫的,所以當我嘗試時,它只是給出了很多錯誤消息。

所以我想我應該只是移動HTML/JavaScript的上面到舊服務器,並告訴它指向Web服務在新服務器上:

我做到了,改變了以上一點點指向腳本新服務器:再次

http://server2/webservice.asmx/GetDayCount 401 (Unauthorized) 
http://server2/webservice.asmx/GetDayCount Origin http://server1 is not allowed by Access-Control-Allow-Origin. 
XMLHttpRequest cannot load http://server2/webservice.asmx/GetDayCount. Origin http://intranet is not allowed by Access-Control-Allow-Origin. 

所以我改變了上面一個小的腳本,通過改變:

url: 'http://server2/webservice.asmx/GetCount', 

它給了以下信息位到jsonp,因爲我認爲jsonp允許跨域?

dataType: 'jsonp', 

但是這並沒有解決任何問題,我現在越來越:

GET http://server2/webservice.asmx/GetCount?callback=jQuery…2680346152&{strMeetingDate:%20%2201/07/2013%2013:00:00%22}&_=1372680346153 500 (Internal Server Error) 

任何人都知道爲什麼,這是行不通的,因爲互聯網服務和腳本在新的服務器時,都明確上工作文件一起在同一臺服務器上。

回答

1

看看this的話題。

It is not possible to do an asynchronous POST to a service on another domain, due to the (quite sensible) limitation of the same origin policy. JSON-P only works because you're allowed to insert <script> tags into the DOM, and they can point anywhere.

關於how jsonp works

相關問題