文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>js访问asp.net后台方法

js访问asp.net后台方法

时间:2010-08-25  来源:寻找GIS

function GetList() {
 document.getElementById("ListBox1").options.length=0;
 var param=getDDLTextandValue();
        var url = "GetUserList.aspx?SessionName=" + encodeURI(encodeURI(param));
        send_request(url);
    }

    var XML_Http_Request = false;
    function createXMLHttpRequest() {
        XML_Http_Request = false;

        if (window.XMLHttpRequest) {
            XML_Http_Request = new XMLHttpRequest();
            if (XML_Http_Request.overrideMimeType) {
                XML_Http_Request.overrideMimeType("text/xml");
            }
        }
        else if (window.ActiveXObject) {
            try {
                XML_Http_Request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    XML_Http_Request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) { }
            }
        }
    }

    function send_request(url) {
        createXMLHttpRequest();
        if (!XML_Http_Request) {
            window.alert("Cannot create XMLHttpRequest instance!");
            return false;
        }
        XML_Http_Request.onreadystatechange = process_Request;
        XML_Http_Request.open("GET", url, true);
        XML_Http_Request.send(null);
    }
    function process_Request() {
        if (XML_Http_Request.readyState == 4) {
            if (XML_Http_Request.status == 200) {
var xmlDoc=XML_Http_Request.responseText;
//var xx=xmlDoc.split(',');
//for(var i=0;i++;i<xx.length)       
//{
//if(xx[i]!="")
//{
//var yy=xx[i].split('|');
//LISTAddNew(yy[0],yy[1],DropDownList1);
//}

//}  

 

 var str2=new Array();
    str2=xmlDoc.split(",");
    var list1=document.getElementById("ListBox1");
    for(i=0;i<str2.length;i++)
    {
    if(str2[i]!="")
    {
     var yy=new Array();
     yy=str2[i].split("|");
     var newOption11=new Option(yy[0],yy[1]);
            list1.options.add(newOption11);
        }
    }
            }

 

 

调用 GetList
        }
    }

 

后台取值页面(GetUserList)代码:

 

    string Groupid = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        Groupid = Request.QueryString["SessionName"];
        try
        {
            OleDbConnection myconn = new OleDbConnection();

            myconn.ConnectionString = ConfigurationManager.ConnectionStrings["strconn"].ConnectionString;
            myconn.Open();
            OleDbCommand mycomm = new OleDbCommand();
            if (Groupid == "-1")
                mycomm.CommandText = "select * from TGroup_User order by userid";
            else
                mycomm.CommandText = "select * from TGroup_User where Groupid=" + Groupid + " order by userid";
            mycomm.CommandType = CommandType.Text;
            mycomm.Connection = myconn;
            OleDbDataReader mydr = mycomm.ExecuteReader();

            string s = "";

            if (mydr.HasRows)
            {
                while (mydr.Read())
                {
                    s = s + ',' + mydr["UserId"].ToString();
                }
            }

            if (s.Length != 0)
            {
                s = s.Substring(1, s.Length - 1);
            }
            else
            {
                s = "-100";
            }
            //Response.Write(s);
            mydr.Close();
            string sql = "";
            if (Groupid == "-1")
                sql = "select * from TUser where IsAdminUser = '1' order by Country DESC, UserName";
                else if(Groupid == "-2")
                sql = "select * from TUser where IsAdminUser = '0' order by Country DESC, UserName";
            else
                sql = "select * from TUser where UserId in (" + s + ") order by Country DESC, UserName";
            string content = string.Empty;
            mycomm.CommandText = sql;
            mydr = mycomm.ExecuteReader();
            if (mydr.HasRows)
            {
                while (mydr.Read())
                {
                    content = content + ',' + mydr["UserName"].ToString();
                    content = content + '|' + mydr["UserId"].ToString();
                }
            }
            myconn.Close();
            mycomm.Dispose();
            mydr.Close();
           Response.Write(content);
           Response.End();
//             DataSet custds = new DataSet();
//custds.Load(mydr,LoadOption.OverwriteChanges,new string[] { "TableName" });

//Response.Write(custds.GetXml());
//            Response.End();       
         
        }
        catch (Exception ex)
        {
        
        }
        finally
        {
        }
    }

 

 

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载