//生成Http请求对象,用于客户端向服务/端发送异步的http请求
function getHttpObject()
{
var _http;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
//如果用户使用IE,就返回XMLHTTP的ActiveX对象
_http = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
else//非IE
{
//否则返回一个XMLHttpRequest对象
_http = new XMLHttpRequest();
}
return _http;
}
//获取全局的HTTP请求对象
var http = getHttpObject();//也可以在顶端声明
//处理请求状态变化
function getHello()
{
//4表示请求已完成
if (http.readyState == 4) //这里的http是全局变量
{
//获取服务段的响应文本
var helloStr = http.responseText;
//alert(helloStr);
if(helloStr.charAt(0)!="0")//表示已经存在
{document.getElementById("showmessage").value="用户名已存在";}
}
}
function CheckUserName()
{
if(document.getElementById("usernametxt").value!="")
{
var url = "usrCheck.aspx?id="+document.getElementById("usernametxt").value; //指定服务端的地址
http.open("GET", url, true);
//请求状态变化时的处理函数
http.onreadystatechange = getHello;
//发送请求
http.send(null);
}
}
这段代码在本机可以执行,但放到服务器,无反应,是怎么回事?
function getHttpObject()
{
var _http;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
//如果用户使用IE,就返回XMLHTTP的ActiveX对象
_http = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
else//非IE
{
//否则返回一个XMLHttpRequest对象
_http = new XMLHttpRequest();
}
return _http;
}
//获取全局的HTTP请求对象
var http = getHttpObject();//也可以在顶端声明
//处理请求状态变化
function getHello()
{
//4表示请求已完成
if (http.readyState == 4) //这里的http是全局变量
{
//获取服务段的响应文本
var helloStr = http.responseText;
//alert(helloStr);
if(helloStr.charAt(0)!="0")//表示已经存在
{document.getElementById("showmessage").value="用户名已存在";}
}
}
function CheckUserName()
{
if(document.getElementById("usernametxt").value!="")
{
var url = "usrCheck.aspx?id="+document.getElementById("usernametxt").value; //指定服务端的地址
http.open("GET", url, true);
//请求状态变化时的处理函数
http.onreadystatechange = getHello;
//发送请求
http.send(null);
}
}
这段代码在本机可以执行,但放到服务器,无反应,是怎么回事?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货