总是报64行没有对象,把所有的Ajax的东西去掉就不报了?为什么

踏实再出发 2010-06-25 11:31:28
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
var XMLHttpReq;
function uc(){

alert("ghjgjkhkj");
}
function check(){
alert("haosayou");
var name=document.getElementById("username").value;
if(name==""){
alert("用户名不能为空");
}else {
sendmsg('ActionServlet');
}
}
function sendmsg(url){
createXMLHttpRequest();
XMLHttpReq.onreadystatechange=calback;
XMLHttpReq.open("post",url,true);
XMLHttpReq.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
XMLHttpReq.send("name="+ encodeURI(encodeURI(name)));
}
function XMLHttpRequest(){
if(window.XMLHttpRequest){
XMLHttpReq=new XMLHttpRequest();

}else if(window.ActiveXObject){
try{
XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
}
function calback(){
if (XMLThhpReq.readyState==4){
document.getElementById("show").innerHTML("正在查询,请等待。。。。。。。");
}else if(XMLHttpReq.status==200){
var text=XMLHttpReq.responseText;
document.getElementById("show").innerHTML("<font size=3 color=blue >"+text+"</font>");
else{
alert("您请求的页面有误")}
}
}


</script>

</head>

<body>
<form action="">
用户名:
<input type="text" name="username">
<input type="button" name="check" onclick="check()" value="检测是否可用">
<br>
<div id="show"></div>
密 码:
<input type="text" name="userpass">
<br>
</form>
</body>
</html>
...全文
57 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Justin-Liu 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 licip 的回复:]
XMLHttpReq.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
这个不对吧。
XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
这样才对吧。
[/Quote]
对啊 怎么写成下划线了
licip 2010-06-25
  • 打赏
  • 举报
回复
XMLHttpReq.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
这个不对吧。
XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
这样才对吧。
hoojo 2010-06-25
  • 打赏
  • 举报
回复

XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
踏实再出发 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 showbo 的回复:]
createXMLHttpRequest();

没见你有这个函数啊?
[/Quote]
这个真有,我把button 的name属性去掉,callback中格式不对的地方改了就不报错了,但是URL开始报错,URL=“ActionServlet?name=“+name;把url中的”/“去掉,解决了,主要还是自己不够细心,以后类似问题我会多多注意了,谢谢大家的回复
Go 旅城通票 2010-06-25
  • 打赏
  • 举报
回复
createXMLHttpRequest();

没见你有这个函数啊?
踏实再出发 2010-06-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 licip 的回复:]
XMLHttpReq.setRequestHeader("Content_Type","application/x-www-form-urlencoded");
这个不对吧。
XMLHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
这样才对吧。
[/Quote]
好像不是这个问题,我把所有关于AJax的代码去掉就能整车个调用JS,但是加上Ajax方法后就不能用了总提示
“对象不支持此属性或方法,提示出错行数是</head>这行”.

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧