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 メソッド」というエラーが再び表示されます。
キャッシュの問題だと思います。
この種のキャッシュを強制的に無効にする方法を知っていますか?