#2
wyq032008-07-31 14:18
|
<%@ 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();" 缺少对象,求高手解答一下,谢谢!