jQuery ajax を使用して、アプリケーションにある aspx ページで WebMethod を呼び出そうとしています。私はこの記事に従っています: http://encosia.com/using-jquery-to-directly-call-aspnet-ajax-page-methods/
ajax 呼び出しを実行しようとすると、WebMethod の結果ではなく、ページ自体 (myPage.aspx) が表示されることに気付きました。この時点で、基本的に上記の記事のコードをそのまま使用しています。JavaScriptは次のとおりです。
$(document).ready(function () {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "myPage.aspx/GetDate",
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);
}
});
});
});
WebMethod の myPage.aspx コード ビハインドは次のとおりです。
[WebMethod]
public static string GetDate()
{
return DateTime.Now.ToString();
}
奇妙なことに、別のテスト ページで動作させたのですが、それを使用したい実際のページに統合しようとすると、統合されません。サイトや Web を検索しても、問題を解決するものは見つかりませんでした。
Sitecore 6.5 と .NET Framework バージョン 4.0 を実行しています。誰でも助けたり、洞察を提供したりできますか?