WebMethodを動作させるのに問題があります。それはすべて正しく設定されており、私はそれを最小の例に単純化しました。AJAXはWebMethodを起動しませんが、成功するとHTMLページ全体を返します
AJAX:(System.Web.Servicesを用いfaq.aspx.csで、;そしてパブリック静的)
function DoAJAX() {
$.ajax({
type: 'POST',
url: 'faq.aspx/DoAJAX',
data: "AJAX Test",
dataType: 'text',
success: function (data, status) {
debugger;
alert(status + " " + data)
},
error: function() {
alert("error!")
}
});
}
WebMethod属性:
[WebMethod]
public static string DoAJAX(string foo) {
return foo;
}
}
HTML (faq.aspx、のScriptManagerとEnablePageMethods付き)
<%@ Page Title="" Language="C#" MasterPageFile="~/MP.Master" AutoEventWireup="true" CodeBehind="faq.aspx.cs" Inherits="Lottery.faq" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<input type="button" value="AJAX" onclick="DoAJAX()" />
</asp:Content>
クリック、AJAX呼び出しがデータに以下の内容で成功を返すとき:http://pastebin.com/X0Vke0qj
ブレークポイントin DoAJAX()WebMethodには決して行きません。
は、なぜそれがWebMethod属性がヒットしなかった理由は、送信された「AJAXテスト」の文字列を返さないのですか?
私はちょうどそれを試してみました、と私は同じを取得返信(データ= HTML文書全体)。 WebMethodのブレークポイントは起動されません。 – Tiago
あなたの 'web.config'に' httpModules'の下に 'ScriptModule'も登録されていますか?それが欠けている場合、どちらもうまくいかないでしょう。 – Scott
Scott:web.configにScriptModuleがありません(かなり空です)。何を追加したらいいですか?また、以前の提案はうまくいかなかった。 ( "エラー!") – Tiago