JSP页面中的button按钮的onclick事件不能触发,从新发布也没用,两个button按钮都没有用。
求指点。<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
try{
xmlHttp=new XMLHttpReques();
}catch(e){
try{
xmlHttp=new ActiveXObject(Msxm12.XMLHTTP);
}catch(e){
try{
xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
}catch{
alert("你的浏览器版本太老了!");
}
}
}
}
function handlestatechange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert("文件内容:"+xmlHttp.responseText);
}
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange=handlestatechange;
xmlHttp.open("post","web.xml",true);
xmlHttp.send(null);
}
function start(){
alert("11111111111");
}
</script>
<body>
This is my JSP page. <br>
<input type="button" id="bt1" value="提交" onclick="startRequest();">
<input type="button" id="bt2" value="测试" onclick="start();">
</body>
求指点。<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
try{
xmlHttp=new XMLHttpReques();
}catch(e){
try{
xmlHttp=new ActiveXObject(Msxm12.XMLHTTP);
}catch(e){
try{
xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
}catch{
alert("你的浏览器版本太老了!");
}
}
}
}
function handlestatechange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert("文件内容:"+xmlHttp.responseText);
}
}
}
function startRequest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange=handlestatechange;
xmlHttp.open("post","web.xml",true);
xmlHttp.send(null);
}
function start(){
alert("11111111111");
}
</script>
<body>
This is my JSP page. <br>
<input type="button" id="bt1" value="提交" onclick="startRequest();">
<input type="button" id="bt2" value="测试" onclick="start();">
</body>
解决方案 »
- jxl excel 添加公式报错 (在线等答案)
- 高分求jsp页面乱码
- IO Connection reset !java.sql.SQLException: Already closed,可能是DBCP的问题。。
- struts validation.xml中其他验证方法都可以,就是mask无效啊,换了好多正则表达式尝试,也没效果啊。我用的是struts1.1 跟版本有关系吗
- 大家都知道hbiernate 的分页特性,但是今天就遇到怪事了!
- Hibernate报错了:org.hibernate.PropertyAccessException
- 这段话什么意思~~~ 苦脑啊!!
- 找不到好答案!!getServletContext()不是一个静态方法,为什么jsp中可以直接调用呢?
- 关于J2EE 下打开j2ee server的奇怪问题
- 关于动态扩展:在运行时载入类和接口动态扩展我们的程序
- 求解决方案:异构数据库数据同步问题-利用hibernate
- 高手帮我看下这报的什么莫名其妙的错误
可以点击页面左下角的js错误提示看一下是什么错误。
xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
}catch{
alert("你的浏览器版本太老了!");
}
catch少了(e)还有你js中还有很多错误、、
给分吧、哈哈
就 catch 后面少了 e ,加上后就正常了,还有什么地方错。说来看看,说不全部给全分,你太打击我了!11
简单一点的直接用错误控制台
工具 - 错误控制台 5.0以上在快捷菜单 - web开发人员 - 错误控制台更进一步的话,安装firebug插件,可以跟踪js执行情况
<html>
<head>
<title>test</title>
<script type="text/javascript">
function test(){
alert("test");
}
function startS(){
alert("11111111111");
}
</script>
</head>
<body>
<body>
<input type="button" id="bt1" value="提交" onclick="startRequest();">
<input type="button" id="bt2" value="测试1" onclick="startS()">
<input type="button" id="bt3" value="测试2" onclick="test()">
</body>
</html>start()这个方法是js内部的,你不能随便叫这个名字啊
<html>
<head>
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}function state_Change()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
{
alert("文件内容:"+xmlhttp.status);
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.responseText);
}
}
}
function startz(){
alert("11111111111");
}
</script>
</head><body>
<h2>Using the HttpRequest Object</h2>
<button onclick="startz()">TEST</button>
<button onclick="loadXMLDoc('c:/web.xml')">TEST_XML</button>完整的ajax代码
var xmlHttp;
function createXMLHttpRequest(){
try{
xmlHttp=new XMLHttpRequest();
}catch(e){
try{
xmlHttp=ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
xmlHttp=ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("浏览器版本过旧!");
}
}
}
}
function startTest(){
createXMLHttpRequest();
xmlHttp.onreadystatechange=test();
xmlHttp.open("post","test.txt",true);
xmlHttp.send(null);
}
function test(){
if(xmlHttp.readyState==4){
alert("test文档内容:"+xmlHttp.responseTest);
}
}
</script>
<body>
<input type="submit" id="bt_1" value="创建XMLHttpRequest对象" onclick="startTest();">
</body>onclick事件可以发生,但是不能得到相应的弹出窗口和信息,使用firedebug 得到的结果 readyState=0 ,
把代码中改为 xmlHttp.readyState==0 时 可以得到弹出窗口 ,但是提示 “test文档内容:undefined”本人新手求解答。
startRequest();
}
<%
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>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
try{
xmlHttp=new XMLHttpRequest();
}catch(e){
try{
xmlHttp=ActiveXObject("Msxm12.XMLHTTP");
}catch(e){
try{
xmlHttp=ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("浏览器版本过旧!");
}
}
}
}
function startTest(){
createXMLHttpRequest();
if(xmlHttp!=null){
xmlHttp.onreadystatechange=test();
xmlHttp.open("post","F:\workspace\java\ajax\WebRoot.txt",true);
xmlHttp.send(null);
}
}
function test(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
alert("test文档内容:"+xmlHttp.responseTest);
}else{
alert("xmlHttp.status:"+xmlHttp.status);
}
}else{
alert("xmlHttp.readyState:"+xmlHttp.readyState);
alert("xmlHttp.status:"+xmlHttp.status);
[color=#FFFF00] alert("txt文件内容:"+xmlHttp.responseText);[/color]
}
}
</script>
<body>
<input type="submit" id="bt_1" value="创建XMLHttpRequest对象" onclick="startTest();">
</body>
</html>代码经过修改还有一点问题。求指点!
1.代码执行了红色字体部分,使用 firedebug发现 readyState=0,status=0;为什么他们的数值是0?
2.另外黄色字体部分 执行结果中xmlHttp.responseText没有结果,是空的,但txt文件中确实有字符啊! 求指点?谢谢
这都写错了