1

JScript+ASP.NETを使用しています。2つの入力(ユーザーとパスワード)とボタンを備えたフォームを取得しました。私がやろうとしていることは次のとおりです。

1- Fire a click event
2- Look inside a database if the user exist
3- Give back the answer
4- If the answer is true, POST some data to an other page AND redirect to it.

私は最初にASP.NETでこれを実行しようとしました。ASP.NETでデータをPOSTするには、PostBackUrlプロパティを使用する必要がありますが、問題は、PostBackUrlがクリックイベントを無視することです。

次に、jscriptを使用してこれを実行しようとしました。クリックイベント(jquery)で、$。ajaxを使用してデータをPOSTしてデータベースにアクセスし、jsonで回答を返します...そしてそこで立ち往生しています。どちらの方法でも、私はポイント4で立ち往生しています。

ASP.NET

protected void SignIn_OnClick(object sender, EventArgs e)
    {
        Clients client = (Clients)clientDAO.getUsername(text1.Text, password2.Text);
        if (client != null)
        {
            Session.Add("SessionNoClient", "1272");
            Session.Add("CurrentQuote", "-1");
            Session.Add("UnitSystem", "0");
            Session.Add("SessionAdministrator", "0");

            //How to redirect with POST here

        }
    }

JScript:

$("#m_bLogin").click(function () {
    var username = $("#text1").val();
    var password = $("#password2").val();
    var form = $("#formClient");
    $.ajax({
        url: '../../Class/LoginAjax.asmx/GetLoginInformation',
        data: "{ 'Name':'" + username + "','Password':'" + $("#password2").val() + "'}",
        dataType: "json",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            //My Json returns {"'Name':'Bob','Password':'1234'} and I'm not able to access Name or Password property. I tried data.d, data.d.Name, eval(data.d.Name) etc...
            form.submit();
        },
        error: function (XMLHttpRequest, textStatus, error) {
            alert(error);
        }
    });
});
4

1 に答える 1

0

あなたはそのようなことをすることができます:

$.ajax({
    url: '../../Class/LoginAjax.asmx/GetLoginInformation',
    data: "{ 'Name':'" + username + "','Password':'" + $("#password2").val() + "'}",
    dataType: "json",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    success: function (data) {
        //My Json returns {"'Name':'Bob','Password':'1234'} and I'm not able to access Name or Password property. I tried data.d, data.d.Name, eval(data.d.Name) etc...
        form.submit();
    },
    error: function (XMLHttpRequest, textStatus, error) {
        alert(error);
    }
}).done(function() { 
                      window.location.href = "YourNewPage.aspx";
                   });
于 2012-09-06T19:35:12.597 に答える