加菲猫

博客园 首页 新随笔 联系 订阅 管理

客户端代码:

  

function AjaxGetData(url) {
            url 
= 'Handler.ashx?what=' + escape('时间');
            
if (window.XMLHttpRequest) {
                
// browser has native support for XMLHttpRequest object 
                req = new XMLHttpRequest();
            }

            
else if (window.ActiveXObject) {
                
// try XMLHTTP ActiveX (Internet Explorer) version 
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }


            
if (req) {
                req.onreadystatechange 
= timeHandler;
                req.open(
'POST', url, true);
                
//req.setRequestHeader("content-type", "application/x-www-form-urlencoded");
                req.setRequestHeader("content-type""text/xml;charset=utf-8");
                req.send(
'');
            }

            
else {
                alert(
'Your browser does not seem to support XMLHttpRequest.');
            }

        }


    
    function timeHandler() {
            try {
                //readyState of 4 or 'complete' represents 
                //that data has been returned 
                if (req.readyState == 4 ||
            req.readyState == 'complete') {
                    document.getElementById('NewTime').innerHTML = req.responseText;

                }
            }
            catch (e) {
                alert('Error in Ajax respone');
            }
        }
服务器端ashx代码
  1:context.Server.UrlDecode(context.Request["what"]);
  2:byte[] Bytes = System.Text.Encoding.Unicode.GetBytes(context.Request["what"].ToString());
       
string original1 = System.Text.Encoding.Unicode.GetString(Bytes);
  3:其它:服务器端解析传过来的xml数据
    public XmlDocument getArgs(context.Request.InputStream inputStream)
  {    
   byte[] bu=new byte[inputStream.Length];
   System.Xml.XmlDocument xmlArgs=new XmlDocument();
   inputStream.Read(bu,0,bu.Length);
   xmlArgs.LoadXml(Encoding.UTF8.GetString(bu,0,bu.Length));
   return xmlArgs;
}

posted on 2008-05-28 14:44  bjh  阅读(1315)  评论(0编辑  收藏  举报