注册 登录
编程论坛 jQuery论坛

求助

mico 发布于 2008-07-28 16:52, 2326 次点击
<%@ 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>
        <base href="<%=basePath%>">

        <title></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">
    -->
        <script src="./json.js"/>
    
        <script language="javascript">
    function doQuery()
    {
        alert(1);
        return;
        var car = getCarObject();
        
        var carAsJSON=JSON.stringify(car);
        alert("Car object as JSON:\n"+carAsJSON);
        
        var url = "JSONExample?timeStamp=" + new Date().getTime();
        
        createXMLHttpRequest();
        xmlHttp.open("POST",url,true);
        xmlHttp.onreadystatechange = handleStateChange;
        xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
        
        xmlHttp.send(carAsJSON);
    }
    
    function createXMLHttpRequest()
    {
        alert(1);
        return;
        if(window.ActiveXObject)
        {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else if(window.XMLHttpRequest)
        {
            xmlHttp = new XMLHttpRequest();
        }
    }
    
    function handleStateChange()
    {
        if(xmlHttp.readyState == 4)
        {
            if(xmlHttp.status == 200)
            {
                parseResults();
            }
        }
    }
    
    function parseResults()
    {
        var responseDiv = document.getElementById("serverResponse");
        if(responseDiv.hasChildNodes())
        {
            responseDiv.removeChild(responseDIV.childNodes[0]);
        }
        
        var responseText = document.createTextNode(xmlHttp.responseText);
        responseDiv.appendChild(responseText);
    }
    
    function getCarObject()
    {
        return new Car("Dodge","Coronet R/T",1968,"yellow");
    }
    
    function Car(make,model,year,color)
    {
        this.make = make;
        this.model = model;
        this.year = year;
        this.color = color;
    }
    </script>
    </head>

    <body>
        <form>
            <input type="submit"
                value="Click here to send JSON data to the server"
                onClick="doQuery();" />
        </form>
        <h2></h2>
        <div id="serverResponse"></div>
    </body>
</html>


为什么我点按钮后老说onClick="doQuery();" 缺少对象,求高手解答一下,谢谢!
2 回复
#2
wyq032008-07-31 14:18
楼主,如果我没猜错的话.你的     <  script src="./json.js"/ > 这个JS,没有引用到.或者 json.js 方法有问题.
#3
mico2008-08-03 13:17
感谢,我在后面加了</script>就好了,我先以为在<script src="./json.js"/ >,后面加一个"/"就可以不用写</script>,BS一下这么多看帖不回的
1