ajax中出现中文乱码和缓存的问题的解决方法

来源:互联网 发布:win7下安装mac双系统 编辑:程序博客网 时间:2024/05/17 02:00

中文乱码:用 encodeURI("解决中文乱码")

解决浏览器缓存:传值的时候加上 new Date().getTime()

示例如下:

var ajax=null;try {    ajax=new XMLHttpRequest()}catch(e) {    ajax=new ActiveXObject("Microsoft.XMLHTTP")}ajax.open("get","a.php?name="+encodeURI('张三')+"&age=20&"+new Date().getTime(),true)ajax.send()ajax.onreadystatechange=function(){    if(ajax.readyState==4){        if(ajax.status==200){            console.log(ajax.responseText)        }    }else{        console.log(ajax.status)    }}