2

asp.net Webサイト(vb.net 2.0を使用)で(jQueryを介して)Ajaxを使用しようとしています。

これが私の .aspx ページ (ajax.aspx) です。

    <%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb" Inherits="_Ajax" %>

<!DOCTYPE html>
<html>
<head>
  <title>Calling page methods with jQuery</title>
  <style type="text/css">
    #Result {
      cursor: pointer;
    }
  </style>
</head>
<body>
  <div id="Result">Click here for the time.</div>

  <script src="jquery-1.8.3.js"></script>
  <script>
      $('#Result').click(function () {
          $.ajax({
              type: "POST",
              url: "ajax.aspx/HelloWorld",
              data: "{}",
              contentType: "application/json; charset=utf-8",
              dataType: "json",
              success: function (msg) {
                  // Replace the div's content with the page method's return.
                  $("#Result").text(msg.d);
              },
              error: function (xhr, ajaxOptions, thrownError) {
                  alert("xhr.responseText= " + xhr.responseText);
                  alert("xhr.responseStatus= " + xhr.responseStatus);
                  alert("thrownError= " + thrownError);
              }
          });
      });
  </script>
</body>
</html>

コード ビハインド ファイル (ajax.aspx.vb) は次のとおりです。

    Imports System
Imports System.Web.Services

Public Class _Ajax
    Inherits System.Web.UI.Page

    Protected Sub Page_Load()

    End Sub

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

End Class

div をクリックすると、ajax 呼び出しが次のエラーで失敗しました。

System.ArgumentException: 不明な Web メソッド HelloWorld.

[編集]

ブラウザを何度も更新して再起動すると、web メソッドが見つかりました。

新しい Web メソッドを追加しようとしましたが、「不明な Web メソッド」というエラーが再び表示されます。

キャッシュの問題だと思います。

この種のキャッシュを強制的に無効にする方法を知っていますか?

4

2 に答える 2

1

最後に、パリトッシュの回答が役に立ちました。

ASP.NET 2.0 を使用して Web サーバーに ASP.NET Ajax 1.0 をインストールする必要がありました。

リンクは次のとおりです 。 http://www.microsoft.com/en-us/download/details.aspx?id=883

その後、ISS の Web サイトを再起動するまで Web メソッドが見つかりません。理由はわかりませんが、再起動すると問題ありません。

回答ありがとうございます。

于 2013-01-16T10:14:07.830 に答える
0

変化する

<%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb"
 Inherits="_Ajax" %>

 <%@ Page Language="vb" AutoEventWireup="true" CodeFile="ajax.aspx.vb"
 Inherits="_Ajax" ScriptManager.EnablePageMethods="true" %>

これにより、このページのすべての Web メソッドが JavaScript クライアントから見えるようになります。

于 2013-01-14T11:26:47.773 に答える