ajax的中文问题(后台asp)

使用escape和unescape函数配合使用

 后台语言asp

<%

    response.write(escape("中文测试"))

%>

 

页面js脚本(只写关键部分)

假设返回的resopnseText为value则

 

alert(unescape(value));

 

即可在页面获得正确的中文字符。

反过来,在页面js脚本里面

 

escape("args=中文字符")

 

在后台使用

 

unescape(request.("args"))

 

可以获取args的值

 

xmlHttpRequest创建调用函数如下:

/********************创建ajax异步调用函数*********************/
/*
  使用这种方式创建的对象,必须先 new 出一个对象,然后调用对象实例的方法
  var aj = new $ajax();
  aj.sendPOST(...);
*/
window.$ajax = function(){
    var version = "1.0";
    return {
        //被页面调用的POST方式函数
        sendPOST : function(url, data, callback) {
         return this.send(url, "POST", callback, data);
        },
        //被页面调用的GET方式函数
        sendGET : function(url, callback, args) {
         return this.send(url, "GET", callback, args);
        },
        send : function(url, method, callback, data) {
         var xmlHttp;
         if (window.XMLHttpRequest) {
          xmlHttp = new XMLHttpRequest();
         } else if (window.ActiveXObject) {
          try{
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
          }catch(ex){
             xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
          }
         }
            //将onreadystatechange属性直接赋值给回调方法
         xmlHttp.onreadystatechange = function() {
          if (xmlHttp.readyState == 4) {
           if (xmlHttp.status < 400) {//获取页面并成功返回数据
            (method=="POST") ? callback(xmlHttp) : callback(xmlHttp,data);
           } else {
                  //什么也不做
           }
          }
         }
         //根据不同的请求方式
         if (method=="POST") {
          xmlHttp.open("POST", url, true);
          xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          xmlHttp.send(data);
         } else {
          xmlHttp.open("GET", url, true);
          xmlHttp.send(null);
         }
         try
         {
             return xmlHttp;
         }catch(e)
         {          }
        
        }
    }
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值