不会出现乱码的ajax 方法
时间:2011-03-21 来源:夕阳茶
var proxy = null;
function create() {
if (window.ActiveXObject) {
try
{
proxy = new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e)
{
proxy = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else
{
proxy = new XMLHttpRequest();
}
}
function executeMethod()
{
create();
var str = escape(document.getElementById("txtContent").value);
var params = "cmd=ajax&name=" + document.getElementById("txtContent").value;
proxy.open("post", "Ajax.aspx", true);
proxy.onreadystatechange = readyMethod;
proxy.setRequestHeader("Content-type","application/x-www-form-urlencoded");
proxy.send(params);
}
function readyMethod() {
if (proxy.readyState == 1) {
document.getElementById("btnAjax").value = "已发送";
}
else
{
if(proxy.readyState==4&&proxy.status==200) {
alert(proxy.responseText);
document.getElementById("btnAjax").value = "发送成功";
}
}
}
相关阅读 更多 +