惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
Cisco Talos Blog
Cisco Talos Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
Project Zero
Project Zero
E
Exploit-DB.com RSS Feed
S
Secure Thoughts
K
Kaspersky official blog
L
Lohrmann on Cybersecurity
NISL@THU
NISL@THU
WordPress大学
WordPress大学
N
News and Events Feed by Topic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LINUX DO - 热门话题
小众软件
小众软件
P
Privacy & Cybersecurity Law Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
A
About on SuperTechFans
Hacker News: Ask HN
Hacker News: Ask HN
AWS News Blog
AWS News Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hacker News: Front Page
F
Full Disclosure
Latest news
Latest news
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
T
Troy Hunt's Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Jina AI
Jina AI
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
TaoSecurity Blog
TaoSecurity Blog
G
GRAHAM CLULEY
Forbes - Security
Forbes - Security
V
V2EX - 技术
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Vulnerabilities – Threatpost
C
Cyber Attacks, Cyber Crime and Cyber Security
MongoDB | Blog
MongoDB | Blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
P
Privacy International News Feed
C
Check Point Blog
N
News and Events Feed by Topic

博客园 - Gerald1983

[转载]AJAX 框架 用 Asp.net ajax 还是 Jquery ? [转]触发器 Excel导出报错 Delete File - Gerald1983 - 博客园 SQLServer Service Can't Start - Gerald1983 DataSource of GridView is Excel - Gerald1983 SQL - Using CASE in a JOIN SQL SERVER 与ACCESS、EXCEL的导入导出(转载) Asp.net页面的生命周期 Asp.net页面的生命周期 DataGrid /GridView分页(sqlserver/oracle)-----转载 sql语句中包括单引号和双引号的问题 XmlDocument操作xml文档 (转) Ajax实例转载 Oracle存储过程编写经验和优化措施(转) GridView的美化 - Gerald1983 数据绑定时的前台页面上的逻辑判断 (转) 如何去掉DataTable中的重复行(新增.net 2.0中最新解决方法---简便) (转) C#代码与javaScript函数的相互调用(转)
一个Ajax实例(成本项目)
Gerald1983 · 2008-06-26 · via 博客园 - Gerald1983

前端代码:
<script type="text/javascript" language="javascript">
function  getHttpRequestObject()//创建xmlhttprequest对象
{
    
var xmlhttp;//定义变量,用来创建xmlhttprequest对象
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined')// 创建xmlhttprequest,ajax开始
     {
        try
         {
          xmlhttp = new XMLHttpRequest();//非IE浏览器,用xmlhttprequest对象创建
         }
         catch (e)
         {
          xmlhttp = false;
         }
    }
    else
    {
         try
         {
              xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");//IE浏览器用activexobject对象创建
          } 
          catch (e) 
          {
              try {
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器用activexobject对象创建
                   } 
              catch(e)
               {
                  xmlhttp = false;
                }
          }
    }
    return xmlhttp;      
}
    
function  setMenuVisible(isVisible)//菜单是否显示
    {
        if(isVisible == true)
        {
           document.getElementById("divmenu").style.display = "inline";//显示菜单
           var obj=document.getElementById("txtGroupName");//获取菜单要显示的地方(HTML元素)
           var left=obj.offsetLeft;//获得obj控件距离左边或上层控件的位置
           var top=obj.offsetTop;//获得obj控件距离上边或上层控件的位置
           while(obj!=document.body)//循环获得obj控件在页面的绝对位置
             {    
             left +=obj.offsetLeft;
             top +=obj.offsetTop;
             obj=obj.offsetParent ;
             }
             document.getElementById("divmenu").style.top=document.getElementById("txtGroupName").offsetHeight +top+document.body.offsetTop;
             document.getElementById("divmenu").style.left=left+document.body.offsetLeft;
        }
        else
        {
            document.getElementById("divmenu").style.display = "none";
        }
    }


    var req;
 function  onComplete()
    {   
        var strGroupName=document.getElementById("txtGroupName").value.replace(/^\s+|\s+$/g,"");
        if(strGroupName!="")
        {
        var url;
        url ="CreaditUserAdd.aspx"+"?action=query&groupName="+escape(strGroupName);
        req = getHttpRequestObject();//获得XmlHttpRequset对象
        req.onreadystatechange = processRequest;//请求状态发生变化,回调函数
        req.open("GET",url,true);
        req.send(null);//发送请求
        }
          
    }

 function  fillSuggest(name)
    {
        document.getElementById("txtGroupName").value = name;
        setMenuVisible(false);
        GroupChange(name);
    }

function  processRequest()//回调函数
    {
        if(req.readyState == 4)//接收成功
        {
            setMenuVisible(false);         
            if(req.status == 200)
            {
                var names = req.responseXML.getElementsByTagName("Names")[0].selectNodes("Name");
                clearMenu();
                if(names.length > 0)
                {
                    var newDivHtml = "";
                    for(var i=0;i<names.length;i++)
                    {
                        newDivHtml += "<div style=\"width:150px; align:center; background-color:White; border-right: #cccccc 1px solid;z-index:2; border-left: #cccccc 1px solid;display:\"inline\";\" onMouseOver=\"this.style.background ='#ddefff'\" onMouseOut=\"this.style.background ='#FFFFFF'\" onclick=\"fillSuggest('"+names[i].text+"')\">"+names[i].text+"</div>";
                    }                             
                    document.getElementById("divmenu").innerHTML = newDivHtml;
                    setMenuVisible(true);
                }
            }
            else
            {
                clearMenu();
            }
        } 
    }

 function  clearMenu()
    {
         document.getElementById("divmenu").innerHTML = "&nbsp;";   
         //position:absolute;
    }
    
 function  GroupChange(name)
   {
    var strGroupName;
  
    if(name==null)
       strGroupName=document.getElementById("txtGroupName").value.replace(/^\s+|\s+$/g,"");
    else
       strGroupName=name;
     
    if(strGroupName!="")
    {
        var url;
        url ="CreaditUserAdd.aspx"+"?action=getSize&groupName="+escape(strGroupName);
        req = getHttpRequestObject();
        req.onreadystatechange = setGroupSize;
        req.open("GET",url,true);
        req.send(null);
    }
   }
  
   ///设置集团规模
   function setGroupSize()
   {
    if(req.readyState == 4&&req.status == 200&&req.statusText == "OK")
    {        
        if(req.responseText!="")
        {
            document.getElementById("txtGroupSize").value=req.responseText;
        }
     }
   }

    //信用类型改变
    function dplType_change()
    {
      if(document.getElementById("dplType").value=="1006000003")
      {
        document.getElementById("trGroup").style.display="inline";
        document.getElementById("rfvGroupName").enabled=true;
      }
      else
      {
        document.getElementById("trGroup").style.display="none";
        document.getElementById("rfvGroupName").enabled=false;
      }
    }
    </script>

<input type="text" style="width: 150px;" runat="server" id="txtGroupName" onchange="GroupChange()"
                        onkeyup="onComplete()" />

<asp:DropDownList ID="ddlSalePan" runat="server" Width="150px"></asp:DropDownList>

后端代码:

#region 模糊查询集团
        if (null != Request.QueryString["groupName"] && Request["action"] == "query")
        {
            Response.ContentType = "text/xml";
            Response.AppendHeader("Cache-Control", "no-cache");
            Response.Write(GetSuggestInfo(Request.QueryString["groupName"].Trim()));
            Response.End();
        }
#endregion

#region 获得集团规模
        if (null != Request.QueryString["groupName"] && Request["action"] == "getSize")
        {
            Response.Clear();
            Response.Write(CM_CREDIT_USER.getGroupSize(Request["groupName"]));
            Response.End();
        }
#endregion

#region 保持客户端控件的属性
        if (dplType.SelectedValue == "1006000003")
        {
            if (txtGroupName.Name.Trim() != "")
            {
                txtGroupSize.Attributes["value"] = CM_CREDIT_USER.getGroupSize(txtGroupName.Value.Trim());
            }
            trGroup.Style["display"] = "inline";
            rfvGroupName.Enabled = true;
        }
        else
        {
            trGroup.Style["display"] = "none";
            rfvGroupName.Enabled = false;
        }

#endregion

Business层:

#region GetSuggestInfo
    public string GetSuggestInfo(string strname)
        {

            XmlDocument doc = new XmlDocument();

            XmlNode rootnode = doc.CreateNode(XmlNodeType.Element, "Names", "");

            doc.AppendChild(rootnode);
            DataSet ds = QueryGroupFromBbossByName(strname);
            if (ds != null && ds.Tables[0].Rows.Count<1000)
            {
                foreach (DataRow objRow in ds.Tables[0].Rows)
                {
                    XmlNode subnode = doc.CreateNode(XmlNodeType.Element, "Name", "");
                    subnode.InnerText = objRow["customer_name"].ToString();
                    doc.ChildNodes[0].AppendChild(subnode);
                }
            }
            return doc.InnerXml;
        }

#endregion
#region getGroupSize
        /// <summary>
        /// 根据集团名称获得集团规模
        /// </summary>
        /// <param name="strGroupName">集团名称</param>
        /// <returns>集团规模</returns>
        public static string getGroupSize(string strGroupName)
        {
            string strReturn = "";
            DataSet ds = new CM_GROUP_COST().GetGroupInfoFromBboss(strGroupName);
            if (ds != null && ds.Tables[0].Rows.Count != 0)
            {
                if (ds.Tables[0].Rows[0]["CUSTOMER_SIZE"] == DBNull.Value)
                    return "";
                int nGroupSize = Convert.ToInt32(ds.Tables[0].Rows[0]["CUSTOMER_SIZE"]);
                switch (nGroupSize)
                {
                    case 1:
                        strReturn = "A 类";
                        break;
                    case 2:
                        strReturn = "B 类";
                        break;
                    case 3:
                    case 4:
                        strReturn = "C 类";
                        break;
                    default:
                        strReturn = "";
                        break;
                }
            }
            return strReturn;
        }
#endregion