| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2326 人关注过本帖
标题:求助
只看楼主 加入收藏
mico
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-7-25
收藏
 问题点数:0 回复次数:2 
求助
<%@ 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();" 缺少对象,求高手解答一下,谢谢!
2008-07-28 16:52
wyq03
Rank: 1
等 级:新手上路
威 望:2
帖 子:63
专家分:0
注 册:2005-9-14
收藏
得分:0 
楼主,如果我没猜错的话.你的     <  script src="./json.js"/ > 这个JS,没有引用到.或者 json.js 方法有问题.

别拿无知当个性!
2008-07-31 14:18
mico
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-7-25
收藏
得分:0 
感谢,我在后面加了</script>就好了,我先以为在<script src="./json.js"/ >,后面加一个"/"就可以不用写</script>,BS一下这么多看帖不回的

2008-08-03 13:17
快速回复:求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026262 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved