网上太多方法了,有的能用有的不能用,自己碰到的写下吧
1:下面这个是Get 方法 xmlHttp.open("GET", webFileUrl);一个html表态页,发现返回是乱码,
解决办法,将这个静态页面用notepad打开,另存为UTF-8格式 即可
var xmlHttp ;
function GetDetails()
{
var webFileUrl = "";
//正常后台生成 webFileUrl = window.frames["ifr2"].location.href="getExList.aspx";
webFileUrl="js/ExPreView.html"
//开始取值过程
xmlHttp = CreateHTTPObject();
//正常后台生成 xmlHttp.open("POST", webFileUrl, false);
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", webFileUrl);
xmlHttp.send("");
}
function handleStateChange(){
if(xmlHttp.readystate == 4){
if(xmlHttp.status == 200){
document.getElementById("exlist").innerHTML = xmlHttp.responseText;
}
}
}
function CreateHTTPObject()
{
var xmlhttptemp;
try
{
xmlhttptemp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlhttptemp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
xmlhttptemp = false;
}
}
if (!xmlhttptemp && typeof XMLHttpRequest!='undefined')
{
try
{
xmlhttptemp = new XMLHttpRequest();
}
catch (e)
{
xmlhttptemp=false;
}
}
if (!xmlhttptemp && window.createRequest)
{
try
{
xmlhttptemp = window.createRequest();
}
catch (e)
{
xmlhttptemp=false;
}
}
return xmlhttptemp;
}