zoukankan      html  css  js  c++  java
  • 有XMLHTTP实现无刷新功能[原创]

    Rss.aspx.cs

    using System;
    using System.Data;
    using System.Web;
    using System.Xml;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Power.Rss;

    public partial class Rss : System.Web.UI.Page
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {
            ProblemXML xml 
    = new ProblemXML();
            
    string username = "";
            
    string password = "";
            
    string category = "0";
            
    string pageSize = "20";
            
    string pageIndex = "1";
            
    string subModuleID ="0";

            XmlDocument doc 
    = new XmlDocument();
            
    try
            
    {
                doc.Load(Request.InputStream);
            }

            
    catch
            
    {
                xml.PutError(ProblemXML.INPUT_ERROR);
                
    return;
            }

            
    if (doc.HasChildNodes)
            
    {
                username 
    = doc.DocumentElement.SelectSingleNode("//username"== null ? "" : doc.DocumentElement.SelectSingleNode("//username").InnerText.Trim();
                password 
    = doc.DocumentElement.SelectSingleNode("//password"== null ? "" : doc.DocumentElement.SelectSingleNode("//password").InnerText.Trim();
                category 
    = doc.DocumentElement.SelectSingleNode("//category"== null ? "0" : doc.DocumentElement.SelectSingleNode("//category").InnerText;
                pageSize 
    = doc.DocumentElement.SelectSingleNode("//pageSize"== null ? "20" : doc.DocumentElement.SelectSingleNode("//pageSize").InnerText;
                pageIndex 
    = doc.DocumentElement.SelectSingleNode("//pageIndex"== null ? "1" : doc.DocumentElement.SelectSingleNode("//pageIndex").InnerText;
                subModuleID 
    = doc.DocumentElement.SelectSingleNode("//ModuleID"== null ? "0" : doc.DocumentElement.SelectSingleNode("//ModuleID").InnerText;

            }

            
    //验证
            if (xml.CheckUser(username, password))
            
    {
               
                
    try
                
    {
                    xml.PutProblemXML(Convert.ToUInt32(category), Convert.ToUInt32(pageSize), Convert.ToUInt32(pageIndex), username,subModuleID);
                }

                
    catch(Exception ex)
                
    {
                    xml.PutError(ex.Message);
                }

            }

            
    else
            
    {
                xml.PutError(ProblemXML.INPUT_PASSWORD_ERROR);
            }


        }

    }



    testRss.htm

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        
    <title>XmlHttp测试</title>
        
    <script type="text/javascript">
        
    function testxml()
        
    {
            
            
    var username = document.getElementById("txtUserName").value;
            
    var password = document.getElementById("txtPassword").value;
            
    var pageSize = document.getElementById("PageSize").value;
            
    var pageIndex =document.getElementById("PageIndex").value;
            
    var ModuleID;
            
    var category;
            
            
    for(var i = 0 ;i<document.getElementById("SelSubModule").options.length;i++)
            
    {
                
    if(document.getElementById("SelSubModule").options[i].selected)
                
    {
                    
    var ModuleID = document.getElementById("SelSubModule").options[i].value;
                }

            }

            
    for(var i=0;i<document.getElementById("SelCategory").options.length;i++)
            
    {
                
    if(document.getElementById("SelCategory").options[i].selected)
                
    {
                    category 
    = document.getElementById("SelCategory").options[i].value;
                }

            }

            
    var strXML = "<Client>\r\n<FormData>\r\n"
                strXML 
    +="<username> " + username + "</username>\r\n";
                strXML 
    +="<password>" + password + "</password>\r\n";
                strXML 
    +="<category>" + category + "</category>\r\n";
                strXML 
    +="<pageSize>" + pageSize + "</pageSize>\r\n";
                strXML 
    +="<pageIndex>" + pageIndex +"</pageIndex>\r\n";
                strXML 
    +="<ModuleID>" + ModuleID +"</ModuleID>\r\n";
                strXML 
    += "</FormData>\r\n</Client>" 
                
            
    var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            xmlhttp.open('POST','Rss.aspx',
    false);
            xmlhttp.send(strXML);
            
    if(xmlhttp.readyState == 4)
            
    {
                document.getElementById(
    "div1").innerText= xmlhttp.responseText;
            }


        }

        
         
    function GetSubModule()
        
    {
            xmlModule  
    = new ActiveXObject("Msxml2.XMLHTTP");
            xmlModule.open(
    "get","Rss_SubModule.aspx",true);
            xmlModule.onreadystatechange 
    = ShowModule;
            xmlModule.send(
    null);
        }

        
    function ShowModule()
        
    {
            
    if(xmlModule.readyState == 4)
            
    {
                
    if(xmlModule.status == 200)
                
    {
                    
    var doc = new ActiveXObject("Msxml2.DOMDocument");
                    doc.loadXML(xmlModule.responseText);
                    
    var items = doc.getElementsByTagName("SubModule");
                    
    for(var i = 0; i < items.length ; i++)
                    
    {
                        
    var op = document.createElement("option");
                        op.value 
    = items[i].getElementsByTagName("SubModuleID")[0].firstChild.nodeValue;
                        
    var txt = document.createTextNode(items[i].getElementsByTagName("SubModuleName")[0].firstChild.nodeValue);
                        op.appendChild(txt);
                        document.getElementById(
    "SelSubModule").appendChild(op);
                    }

                    
                }

                
    else
                
    {
                    alert(xmlModule.statusText);    
                }

            }

        }

        
    </script>
    </head>
    <body style="font-size:12px" onload="GetSubModule()">
        
    <div>
            
    <table border="0" cellpadding="2" cellspacing="1" style="background-color: #a9a9a9">
                
    <tr>
                    
    <td style=" 100px; background-color: #ffffff;">
        用户名:
    </td>
                    
    <td style="background-color: #ffffff;">
                        
    <input id="txtUserName" type="text" /></td>
                
    </tr>
                
    <tr>
                    
    <td style=" 100px; background-color: #ffffff;">
        密 
    &nbsp;&nbsp; 码:</td>
                    
    <td style="background-color: #ffffff;">
                        
    <input id="txtPassword" style=" 150px" type="password" /></td>
                
    </tr>
                
    <tr>
                    
    <td style=" 100px; background-color: #ffffff;">
                        页分大小:
    </td>
                    
    <td style="background-color: #ffffff;">
                        
    <input id="PageSize" type="text" value="20" /></td>
                
    </tr>
                
    <tr>
                    
    <td style=" 100px; background-color: #ffffff;">
                        页分索引:
    </td>
                    
    <td style="background-color: #ffffff;">
                        
    <input id="PageIndex" type="text" value="1" /></td>
                
    </tr>
                
    <tr>
                    
    <td style=" 100px; background-color: #ffffff;">
                        模块节点:
    </td>
                    
    <td style="background-color: #ffffff;">
                        
    <select id="SelSubModule" style=" 155px">
                            
    <option selected="selected" value="0">全部类型</option>
                        
    </select>
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td style=" 100px; background-color: #ffffff">
                        分 类:
    </td>
                    
    <td style="background-color: #ffffff">
                        
    <select id="SelCategory" style=" 154px">
                            
    <option selected="selected" value="0">全部问题</option>
                            
    <option value="1">已解决的问题</option>
                            
    <option value="2">未解决的问题</option>
                            
    <option value="3">我解决的问题</option>
                            
    <option value="4">我未解决的问题</option>
                            
    <option value="5">未回复的问题</option>
                            
    <option value="6">回复后又修改的问题</option>
                        
    </select>
                    
    </td>
                
    </tr>
                
    <tr>
                    
    <td colspan="2" style="background-color: #ffffff" align="center">
        
    <input id="Button1" type="button" value="button"  onclick="testxml()"/></td>
                  
                
    </tr>
            
    </table>
            
    <div id="div1" style="background-color:#ffffe9 ;"></div>
        
    </div>
    </body>
    </html>
  • 相关阅读:
    nyoj 69 数的长度
    hdu 1437 天气情况【概率DP】
    hdu 2058 The sum problem
    hdu 1491 Octorber 21st
    Aras学习笔记(16)- Aras官方项目Tree Grid View Sample原理介绍
    Aras学习笔记 (15)
    Aras学习笔记 (14) DotNet操作Aras常用代码代码汇总(陆续更新中)
    Aras学习笔记 (13) Javascript端常用代码代码汇总(陆续更新中)
    Aras学习笔记 (12) C#代码读取域用户列表(转,翻译)
    Aras学习笔记 (11) Aras集成AD账号
  • 原文地址:https://www.cnblogs.com/ghx88/p/441667.html
Copyright © 2011-2022 走看看