0

私は1つのポートlocalhost:5739でasmxサービスを実行しており、他のポートまたはプレーンhtml +プロジェクトからjqueryからサービスを呼び出そうとしています

しかし、私はWebサービスにアクセスできません

私のウェブサービスは

 [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string text) {
    return "Hello World" + text;
}

そして、Webサービスを呼び出す私のコードは

            $.ajax(
            {
                type: "POST",
                url: "http://localhost:5739/asmxservices/testservice.asmx/HelloWorld",
                data: '{ "text": "Kartheek"}',                    
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                error: OnError

            });

            function OnSuccess(data, status) {
                alert(data.d);

            };
            function OnError(msg) {
                alert('error = ' + msg.d);
            }
4

3 に答える 3

1

次のように、メソッドは静的である必要があります。

[WebMethod] 
[ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
public static string HelloWorld(string text) { 
    return "Hello World" + text; 
} 
于 2012-09-13T11:18:19.697 に答える
0

ファイルの配置が原因でお困りのようです。サービスを呼び出す JS コードは、サービスと同じホスト上にある必要があります。プロジェクトのルート フォルダーに html ファイルを配置し、デバッグ中にディレクトリ リストから実行してみてください。サンプルとして: パスを持つサービス呼び出しファイルをテストします

http://localhost:51169/2.html

于 2013-02-26T12:15:08.093 に答える