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>

解决方案 »

  1.   

    一般来说,这是页面js有错误导致的,要测试的话把别的js去掉只留触发事件的代码测试即可
    可以点击页面左下角的js错误提示看一下是什么错误。
      

  2.   

    js错了。用火狐调试js看看什么地方写错了。
      

  3.   

    try{
      xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
      }catch{
      alert("你的浏览器版本太老了!");
      }
    catch少了(e)还有你js中还有很多错误、、
    给分吧、哈哈
      

  4.   


    就  catch 后面少了 e  ,加上后就正常了,还有什么地方错。说来看看,说不全部给全分,你太打击我了!11
      

  5.   

    同样谢谢其他各位,能否给点建议:比如说写JS 的一些注意事项、和建议以及如何发现JS其中的错误。谢谢!
      

  6.   

    还有个问题 :用的 goggle chrome 浏览器  14.0.803.0   居然显示浏览器太老!  这浏览器真有那么老?
      

  7.   

    js差错的好工具:Firefox
    简单一点的直接用错误控制台
    工具 - 错误控制台  5.0以上在快捷菜单 - web开发人员 - 错误控制台更进一步的话,安装firebug插件,可以跟踪js执行情况
      

  8.   

    不能触发很简单,JS代码出错,要不然不存在不能触发的现象,建议使用alert()逐步调试。
      

  9.   

    IE8以上版本的话。直接F12不解释
      

  10.   


    <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内部的,你不能随便叫这个名字啊
      

  11.   


    <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代码
      

  12.   

    出现浏览器版本太来是因为javascript中代码的错误,改正后,有有新问题了:<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();
            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”本人新手求解答。
      

  13.   

    if(xmlHttp.status==200){
       startRequest();
       }
     
      

  14.   

    <%@ page language="java" 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>
        <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文件中确实有字符啊! 求指点?谢谢
      

  15.   

    那位高人指点下,为什么 readyState和status的值都是0.还有 xmlHttp.ResponseText的值是空的,谢谢!
      

  16.   

    xmlHttp=new XMLHttpReques();
    这都写错了