52,797
社区成员
发帖
与我相关
我的任务
分享
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page language="java"%>
<%@ page import="java.sql.*,ajax.db.DBUtils"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>购物车</title>
<script type="text/javascript">
var xmlHttp; //用于保存XMLHttpRequest对象的全局变量
//用于创建XMLHttpRequest对象
function createXmlHttp() {
//根据window.XMLHttpRequest对象是否存在使用不同的创建方式
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest(); //FireFox、Opera等浏览器支持的创建方式
} else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
}
}
//向购物车添加产品
function addProduct(pid) {
sendRequest1("&action=add&pid=" + pid);
}
//向服务器发送操作请求
function sendRequest1(params) {
createXmlHttp(); //创建XmlHttpRequest对象
xmlHttp.onreadystatechange = showCartInfo;
alert(params)
xmlHttp.open("Post", "test.jsp?"+params, true);
xmlHttp.send(null);
}
//将服务器响应信息写入购物车div中
function showCartInfo() {
document.getElementById("shoppingcart").innerHTML = "abc"
}
</script>
</head>
<body onload="refreshCart()">
<h1>购物车</h1>
<table class="default">
<tr>
<td class="item" width="35%">产品名称</td>
<td class="item" width="20%">价格</td>
<td class="item" width="45%">放入购物车</td>
</tr>
<tr>
<td>1</td>
<td align="center">2 元</td>
<td align="center"><input type="button" value="加入购物车" onclick="addProduct('3')"></td>
</tr>
</table>
<table>
<%
String str = request.getParameter("pid");
if(str!=null){
System.out.println(str);
}else{
System.out.println("null");
}
%>
</table>
<!-- 购物车信息 -->
<div id="shoppingcart">
</div>
</body>
</html>
问个问题,我点“加入购物车”这个按钮,请求提交给本页面(还是test.jsp),报了这个错
2008-4-24 6:26:26 org.apache.tomcat.util.http.Parameters processParameters
警告: Parameters: Invalid chunk ignored.
这是什么原因啊?回调函数sendRequest1已经执行了,alert语句都打印了,为什么中间的输出语句没有执行啊?请求发给自己就不行吗?
我把请求发给另一个页面
function sendRequest1(params) {
createXmlHttp(); //创建XmlHttpRequest对象
xmlHttp.onreadystatechange = showCartInfo;
alert(params)
xmlHttp.open("Post", "test2.jsp?"+params, true);
xmlHttp.send(null);
}
这就对了,这是为什么啊
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body>
<%
System.out.println("test2");
%>
</body>
</html>