0

テキストボックスコントロールがあります。スクリプトは

<asp:TextBox ID="txtDate" EnableTheming="false" CssClass="calender" 
                        runat="server" ClientIDMode="Static"></asp:TextBox>

カレンダーコントロールで特定の日付を選択した場合、その特定の日付のデータベースからレコードを取得する必要があるため、テキストボックスの変更イベントを次のように配置してみました

$(function () {
    $('#txtDate').change(function () {
        $.ajax({
            type: "POST",
            url: "/DataService.asmx/fetchAbsentees",
            contentType: "application/json; charset=utf-8",
            data: "{'date' : '" + $("#txtDate").val() + "'}",
            dataType: "json",
            success: function (data) {
                alert("Successfully reached.");
            },
            error: function (req, status, error) {
                alert("ERROR:" + error.toString() + " " + status + " " + req.responseText);
            }
        });
    }).triggerHandler('change');
});

Webサービスはここから正常に起動されますが、アプリケーションを実行するたびに起動されるので、テキストボックスの日付を変更したときにのみ起動されるようにします......誰かがここで私を助けてくれますか。

注:マスターページを使用しています。

4

1 に答える 1

3

次の部分を削除する必要があります。

.triggerHandler('change');

これにより、イベントがすぐに発生します。

最終的なコードは次のようになります。

$(function () {

    $('#txtDate').change(function () {
        $.ajax({
            type: "POST",
            url: "/DataService.asmx/fetchAbsentees",
            contentType: "application/json; charset=utf-8",
            data: "{'date' : '" + $("#txtDate").val() + "'}",
            dataType: "json",
            success: function (data) {
                alert("Successfully reached.");
            },
            error: function (req, status, error) {
                alert("ERROR:" + error.toString() + " " + status + " " + req.responseText);
            }
        });
    });

});
于 2012-04-05T13:45:32.880 に答える