0
我以前用VS2010中的jQuery調用WebMethods時,不再適用於VS2013。這裏是網頁服務代碼:WebMethods不能與VS2013一起工作
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Web.Script.Serialization
<WebMethod()> _
Public Shared Function Test() As String
Dim strTest As String = "Testing"
Return strTest
End Function
這裏是jQuery的調用方法:
function TestService() {
$.ajax({
type: "POST",
url: "myPage.aspx/Test",
contentType: "application/json; charset=utf-8",
data: '[]'
})
.done(function (d) {
alert('success');
})
.fail(function (xhr, st, err) {
alert('failed');
});
}
正如你能猜到我總是得到失敗的警報。這在2010年完美運行。在文檔中找不到任何新東西。
忘了補充 - 錯誤是「內部服務器錯誤」,通常意味着jQuery無法找到您指向該方法的url。我確實在webmethod Test中設置了一個斷點,我們沒有到達那裏。 –
您的ajax請求中的數據不是字符串,而是對象。 500通常意味着你發送了不正確的數據。檢查網絡選項卡以確認這一點。 – GuyT
謝謝@GuyT - 工作 - 一起刪除了數據參數,它工作。我也可以將其更改爲數據:'{}'如果您做出答案,我會標記它。 –