24h購物| | PChome| 登入
2011-08-02 10:15:33| 人氣2,596| 回應1 | 上一篇 | 下一篇

[ExtJS] Ajax 登入帳號密碼 傳值練習

推薦 0 收藏 0 轉貼0 訂閱站台

//--login.aspx
Ext.onReady(function () {
/*-------------------------------函數:傳送取得值------------------------------------------*/
        function trans_login(login_name, login_pass) {
            //var trans_data = login_name + login_pass;
            Ext.Ajax.request({
                method: 'POST',
                params: {
                    send_name: login_name,
                    send_pass: login_pass
                },
                url: '/back.aspx',
                success: function (request) {
                    var message = request.responseText;
                    Ext.Msg.alert("傳送成功回傳訊息", value_cut(message));
                },
                failure: function () { Ext.Msg.alert("傳送狀態", "err"); }
            });
        };
/*---------------------------------------------------------------------------------------*/

/*-------------------------------函數:切割回傳值------------------------------------------*/
        function value_cut(back_value) {
            var temp = "";
            for (var i = 0; i < back_value.length; i++) {
                if (back_value[i] + back_value[i + 1] + back_value[i + 2] == ";&!") {
                    temp += "<br>";
                    i += 2;
                } else {
                    temp += back_value[i];
                }
            }
            return temp;
        };
/*---------------------------------------------------------------------------------------*/

/*-------------------------------函數:取得欄位值------------------------------------------*/
        function login() {
            //alert("123");
            //                var val = new Ext.getCmp("form_p").getForm().findField("name").getValue();
            //                alert(val);
            if (form_p.getForm().findField("name").getValue() == "" || form_p.getForm().findField("password").getValue() == "") {
                Ext.Msg.alert("Error", "帳號或密碼輸入錯誤,請重新輸入!!");
            } else {
                //alert("輸入的帳號為" + form_p.getForm().findField("name").getValue() + "\n" + '輸入的密碼為' + form_p.getForm().findField("password").getValue());
                trans_login(form_p.getForm().findField("name").getValue(), form_p.getForm().findField("password").getValue());
            };
        };
/*---------------------------------------------------------------------------------------*/

        //使用者登入頁面
/*-------------------------------建立FormPanel-------------------------------------------*/
        var form_p = new Ext.FormPanel({
            id: 'form_p',
            frame: true,
            title: '登入',
            width: 400,
            defaults: { width: 200 },
            defaultType: 'textfield',
            items: [
        {
            fieldLabel: 'Name',
            id: 'name'
        }, {
            fieldLabel: 'Password',
            id: 'password',
            inputType: 'password'
        }
        ],
            fbar: [{ id: 'login', xtype: 'button', text: 'Login', listeners: { 'click': function () { login(); } }}],
            renderTo: Ext.getBody()
        });
/*---------------------------------------------------------------------------------------*/
});

//--back.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DemoProject
{
    public partial class back : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Request.Form ,接收以post方式傳遞過來的訊息
            //Request.QueryString ,接收以get方式傳遞過來的訊息
            string name = Request.Form["send_name"].ToString();
            string pass = Request.Form["send_pass"].ToString();

            //string id = "admin",pass = "password";

            //串起前端送過來的字串並加入切割辨識字串";&!"
            string s = "輸入帳號為:" + name + ";&!" + "輸入密碼為:" + pass;
            //回傳字串
            Response.Write(s);

            //if (name == "")
            //{
            //    string message = "內容為空字串";
            //    Response.Write(message);
            //}
            //else
            //{
            //    string message = search;
            //    Response.Write(message);
            //}
        }
    }
}

台長: 迷鼠
人氣(2,596) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 教育學習(進修、留學、學術研究、教育概況) | 個人分類: 網頁程式 |
此分類下一篇:[ExtJS] 取得後端Response的XML內容顯示於前端Grid
此分類上一篇:[ExtJS] Ajax傳值練習

持久液
很讚的分享~~


http://www.yyj.tw/
2020-01-15 18:04:20
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文