zoukankan      html  css  js  c++  java
  • bytes2BSTR 解决ajax中ajax.responseBody 乱码问题

    代码
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>XMLHttp</title>
    <script language="javascript">
    <!--
    /**
    * 初始化一个xmlhttp对象
    */
    function InitAjax()
    {
      
    var ajax=false
      
    try { 
         ajax 
    = new ActiveXObject("Msxml2.XMLHTTP"); 
          } 
      
    catch (e) { 
              
    try { 
                    ajax 
    = new ActiveXObject("Microsoft.XMLHTTP"); 
                  }
             
    catch (E) { 
                    ajax 
    = false
                  } 
                }
        
    if (!ajax && typeof XMLHttpRequest!='undefined') { 
        ajax 
    = new XMLHttpRequest(); 
        } 
        
    return ajax;
      } 
    function show_total(newsID)
    {
    //如果没有把参数newsID传进来
    if (typeof(newsID) == 'undefined')
    {
    return false;
    }
    //需要进行Ajax的URL地址
    var url = "http://192.168.1.208/text.txt?random="+Math.random();
    //获取新闻显示层的位置
    var show = document.getElementById("show_total"); 
    //实例化Ajax对象
    var ajax = InitAjax();
    //使用Get方式进行请求 
    ajax.open("GET", url, true); 
    //获取执行状态
    ajax.onreadystatechange = function() { 
    //如果执行是状态正常,那么就把返回的内容赋值给上面指定的层
    if (ajax.readyState == 4 && ajax.status == 200) { 
    show.innerHTML 
    =  bytes2BSTR(ajax.responseBody); 


    }
    //发送空
    ajax.send(null); 
    }
    //定时开始
    var sec = 0;
    timerID 
    = setInterval("show_total(1)",1000);

     
    //-->
    </script>
    <script type="text/vbscript">
    Function bytes2BSTR(vIn)  
        strReturn 
    = ""  
        For i 
    = 1 To LenB(vIn)  
            ThisCharCode 
    = AscB(MidB(vIn,i,1))  
            If ThisCharCode 
    < &H80 Then  
                strReturn 
    = strReturn & Chr(ThisCharCode)  
            Else  
                NextCharCode 
    = AscB(MidB(vIn,i+1,1))  
                strReturn 
    = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))  
                i 
    = i + 1  
            End If  
        Next  
        bytes2BSTR 
    = strReturn  
    End Function  
    </script> 
    </head>
    <body>
    实时快报:
    <div id=show_total>
    </div>
    </body>
    </html>
  • 相关阅读:
    源码
    Leetcode 230. 二叉搜索树中第K小的元素 中序遍历
    Leetcode 160. 相交链表 哈希 链表
    Leetcode 142. 环形链表 II
    Leetcode 217. 存在重复元素 哈希 排序
    asp.mvc2.0资料
    关于CRM的介绍
    WPf控件模板缺省样式
    皮肤制作工具
    关于linq的用法
  • 原文地址:https://www.cnblogs.com/lgms2008/p/1775184.html
Copyright © 2011-2022 走看看