使用jquery ajax调用Web服务器时出现“NetworkError:500 Internal Server Error”

时间:2012-08-29 08:51:31

标签: jquery ajax vb.net web-services

我正在尝试使用ajax调用web服务。 Web服务是用vb.net编写的。当我直接使用它的url调用它时它工作正常,但当我使用ajax调用它时它会返回

  

NetworkError:500内部服务器错误-http://localhost/chart/webService.asmx/HelloWorld。

这是我的网络服务代码:

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');
        }
    });
});

更新:

我将HelloWorld()更改为以下代码,但仍然收到相同的错误:

<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

1 个答案:

答案 0 :(得分:0)

使用:

data:{},

而不是:

data:"{}",