windful1000 发表于 2008-1-11 15:49

ajax问题(急求助)

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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>提取index.jsp的数据</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">
        -->
   <style type='text/css'>
    * { font-family: Tahoma, Arial, sans-serif; }
    #divId{ color: #48f; }
  </style>       
<script type="text/javascript">
   var XMLHttpReq;
   function createXMLHttpRequest(){
    if(window.XMLHttpRequest)
   XMLHttpReq = new XMLHttpRequest();
  else if(wondow.ActiveXObject)
    XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}

function chuli(){
  if(XMLHttpReq.readyState == 4){
    if(XMLHttpReq.status == 200 || XMLHttpReq.status == 0){
        var divInfo = document.getElementById("divId");
        if(responseDataType != "Text")
           divInfo.innerHTML = XMLHttpReq.responseXML;
        else
           divInfo.innerHTML = XMLHttpReq.responseText;
    }else{
      window.alert("你所请求的页面有异常");
     }
  }
}

function lianjie(){
  var url="index.jsp";
  createXMLHttpRequest();
  XMLHttpReq.onreadystatechange = chuli;
  XMLHttpReq.open("GET",url,true);
  XMLHttpReq.send(null);
}  
</script>
  <!--
  <script type="text/javascript" src="prototype.js"/>
  <script type="text/javascript">
  window.onload=function(){
    new Ajax.Request(
      "index.jsp",
      {
              method:"post",
        onComplete:function(xhr){
          $('divId').innerHTML = xhr.responseText;
  }
    }
    );
} ;  
  </script>
   -->
  </head>
  
  <body onLoad=lianjie();>
    <div id="divId">
        
    </div>
  </body>
</html>


index.jsp页面里有数据
可是我的这个页面取不到数据是什么原因啊

不惑 发表于 2008-2-13 15:12

function chuli(){
  if(XMLHttpReq.readyState == 4){
    if(XMLHttpReq.status == 200 || XMLHttpReq.status == 0){
        var divInfo = document.getElementById("divId");
        if(responseDataType != "Text")
           divInfo.innerHTML = XMLHttpReq.responseXML;
        else
           divInfo.innerHTML = XMLHttpReq.responseText;
    }else{
      window.alert("你所请求的页面有异常");
     }
  }
   window.alert(divInfo.innerHTML);
}
这样看看,它是不是真的没传过来

ming206 发表于 2008-2-18 16:45

在:
var divInfo = document.getElementById("divId");下

加:

var scripts = document.getElementById(divInfo).getElementsByTagName("SCRIPT");
                                for (var i = 0; i < scripts.length; i++)
                                {
                                        if (scripts[i].tagName == "SCRIPT")
                                        {
                                                scripts[i].src = scripts[i].src;
                                                scripts[i].defer = true;
                                                scripts[i].type =  "text/javascript";
                                        }
                                }

ming206 发表于 2008-2-18 17:03

弹出有东西,你自己看:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
    <title>提取index.jsp的数据</title>
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
   <style type='text/css'>
    * { font-family: Tahoma, Arial, sans-serif; }
    #divId{ color: #48f; }
  </style>   
<script type="text/javascript">
   var XMLHttpReq;
   function createXMLHttpRequest(){
     if(window.XMLHttpRequest){
         XMLHttpReq = new XMLHttpRequest();
      }
                 else if(window.ActiveXObject){
             try{
                     XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
                    }catch(e){}
                 }
}

function chuli(){
  if(XMLHttpReq.readyState == 4){
    if(XMLHttpReq.status == 200){
        var divInfo = document.getElementById("divId");
        var scripts = divInfo.getElementsByTagName("SCRIPT");               
                                 for (var i = 0; i < scripts.length; i++)
                                 {
                                          if (scripts[i].tagName == "SCRIPT")
                                          {
                                                        scripts[i].src = scripts[i].src;
                                                        scripts[i].defer = true;
                                                        scripts[i].type =  "text/javascript";
                                          }
                                 }
                    alert(XMLHttpReq.responseText);
                          divInfo.innerHTML = XMLHttpReq.responseText;
    }else{
      window.alert("你所请求的页面有异常");
     }
  }
}

function lianjie(){
  var url="index.jsp";
  createXMLHttpRequest();
  XMLHttpReq.onreadystatechange = chuli;
  XMLHttpReq.open("GET",url,true);
  XMLHttpReq.send(null);
}  
</script>
  </head>
  <body onLoad=lianjie();>
    <div id="divId"></div>
  </body>
</html>

页: [1]

编程论坛