0

ajax を使用して Web サービスを呼び出そうとしています。Web サービスは vb.net で記述されています。URLを使用して直接呼び出すと正常に動作しますが、ajaxを使用して呼び出すと返されます

NetworkError: 500 内部サーバー エラー - 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');
        }
    });
});

アップデート:

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
4

1 に答える 1