2013-07-12 254 views
5

我在這個主題上看到了很多問題,但從來沒有這個問題。我可以從瀏覽器窗口調用這個Web服務,但是我從AJAX中得到錯誤。我收到內部服務器錯誤異常(500)。由於Im從本地主機連接,因此可能必須在JQuery中使用我的URL進行操作。這裏是我的WS(簡化版):JQuery - ASP.NET Web服務(.asmx) - 內部服務器錯誤(500)

<System.Web.Script.Services.ScriptService()> _ 
<WebService(Namespace:="http://tempuri.org/webdienst/_default")> _ 
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ 
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _ 
Public Class _default 
    Inherits System.Web.Services.WebService 

    <WebMethod()> _ 
    <ScriptMethod(ResponseFormat:=ResponseFormat.JSON)> _ 
    Public Function getOrganizerEventsJSON(ByVal strUser As String, ByVal strPasswort As String) As TEvent 
     Dim t As TEvent 
     'I get the event for the specified username and password 
     Return t 

    End Function 
End Class 

這裏是我的JS:

var ASMX = "http://localhost:56035/default.asmx/"; 
jQuery.callAsmx = function (method, data, onSuccess, onError) { 
    var url = ASMX + method; 
    return $.ajax({ 
     type: "POST", 
     url: url, 
     data: $.stringify(data), 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function (response) { 
      if (typeof onSuccess == "function") { 
       onSuccess(response.d); 
      } 
     }, 
     error: function (msg) { 
      if (msg.status != 0) { 
       if (typeof onGlobalError == "function") { 
        onGlobalError([msg], 
        "Error while calling " + url, ERRORTYPE.error); 
       } 
       if (typeof onError == "function") { 
        onError(msg); 
       } 
      } 
     } 
    }); 
}; 

$.callAsmx("GetOrganizerEventsJSON", { strUser: username, strPasswort: password }, onEventsLoaded); 

謝謝!

+0

試着用'static'關鍵字'方法public static function(...)'。 –

+1

@DKM Nope ... Web服務類沒有靜態函數。 – lucafik

+0

如果您遇到'500'錯誤,我想這個問題出現在您的服務器端。 – anmarti

回答

2

我有同樣的錯誤,並能解決它:

你應該刪除以下行:

contentType: "application/json; charset=utf-8", 
    dataType: "json",