jquery-ajax(get)呼び出しc#バックグラウンド

1498 ワード

1)フロントaspx
        $(function() {
            var name = "zhcao";
            var password = "870602";
            $.ajax({
                type: "Get",   //  WebService  Get    
                url: "Ajax.aspx",
                data: "name=" + name + "&password=" + password+"&action=test",
                success: function(result) {//    ,result,   
                    alert(result);
                }
            });
        });

2)バックグラウンド(Ajax.aspx.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace JqueryAjaxDemo
{
    public partial class Ajax : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string name = Request.QueryString["name"];
            string password = Request.QueryString["password"];
            string action = Request.QueryString["action"];
            if (action == "test")
            {
                Test();
            }
        }
        public void Test()
        {
            Response.Write("test");
        }
    }
}

Ajax.aspxコードは、より正確な戻り情報を得るために以下のように変更される.
<%@ Page Language="C#"AutoEventWireup="true"CodeBehind="Ajax.aspx.cs"Inherits="WebApplication33.Ajax"%>