2012-08-29 20 views
0

我試圖用ajax調用webservice。該Web服務是用vb.net編寫的。當我把它直接使用它的URL,它工作正常,但是當我使用AJAX調用它返回使用jQuery ajax調用Web服務器時出現「NetworkError:500 Internal Server Error」

NetworkError: 500 Internal Server Error-http://localhost/chart/webService.asmx/HelloWorld.

這裏是我的web服務代碼:

Imports System.Web.Services 
Imports System.Web.Services.Protocols 
Imports System.ComponentModel 

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _ 
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ 
<ToolboxItem(False)> _ 
Public Class webService 
    Inherits System.Web.Services.WebService 

    <WebMethod()> _ 
    Public Function HelloWorld() As String 
     Return "Hello World" 
    End Function 

End Class 

這裏是javascript代碼:

$(document).ready(function() { 
    var webMethod = 'http://localhost/chart/webService.asmx/HelloWorld'; 
    $.ajax({ 
     type: "POST", 
     url: webMethod, 
     data: "{}", 
     contentType: "application/json; charset=utf-8", 
     dataType: "json", 
     success: function(msg) { 
      alert('all good'); 
     }, 
     error: function(e) { 
      alert('err'); 
     } 
    }); 
}); 

UPDATE:

我改變的HelloWorld()下面的代碼,但仍然得到的S AME錯誤:

<WebMethod()> _ 
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ 
Public Function HelloWorld() As String 
    Dim aa As New System.Web.Script.Serialization.JavaScriptSerializer 
    Return aa.Serialize("Hello World") 
End Function 
+0

的功能*程序hello_world」沒有返回JSON對象。 – jancha

+0

更新後可以發帖。但是您仍然在嘗試在瀏覽器中訪問錯誤 –

+0

? – VDP

回答

相關問題