function sendRequest(url){
window.alert("执行到此了---sendRequest(url)函数");
createXMLHttpRequest();
XMLHttpRequest.Open("GET",url,true);//报错行!!!!!
XMLHttpRequest.onreadystatechange=callBack;
XMLHttpRequest.send(null);
XMLHttpRequest.Open("GET",url,true);改成如下也不行
XMLHttpRequest.open("GET",url,true);
请高手们帮个忙,这段代码在和firefox中均报错说:XMLHttpRequest.Open is not a function
在IE7 中报错说:对象不支持此属性或方法
[b]问题补充:[/b]
服务器端是用 out.println(responseText); out.close();能打印responseText的值。以下是jsp页面脚本完整代码,
var XMLHttpRequest;
function createXMLHttpRequest(){
window.alert("执行到此了---createXMLHttpRequest()函数");
if(window.ActiveXObject)//ActiveXObject对象到找到的时候返回的是真,否则是假
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//这个是使用IE的方法创建XmlHttp
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();//这个是使用非IE的方法创建XmlHttp
}
}
function callBack(){
window.alert("执行到此了---callBack()函数");
if(XMLHttpRequest.readyState==4){
if(XMLHttpRequest.status==200){
document.getElementById("result").innerHTML=XMLHttpRequest.ResponseText;
window.alert("返回值是:"+ XMLHttpRequest.ResponseText);
}
}
}
function sendRequest(url){
window.alert("执行到此了---sendRequest(url)函数");
createXMLHttpRequest();
XMLHttpRequest.open("POST",url,true);
XMLHttpRequest.onreadystatechange=callBack;
XMLHttpRequest.send(null);
}
function checkUsername(){
window.alert("您输入的用户名是:"+ $F(username));
window.alert("执行到此了---checkUsername()函数");
var name=document.getElementById("username").value;
sendRequest("CheckUsername?username="+name);
}
[b]问题补充:[/b]
谢谢 ThinkingInAll
不过 XMLHttpRequest.responseText 返回的结果是一连串 ??????
[b]问题补充:[/b]
还有 window.alert("执行到此了---callBack()函数");
中的 “执行到此了---callBack()函数”这句话显示了三遍