ajax提交的问题

wnba1983 2008-04-24 02:31:02
我有个test.jsp,代码如下:

<%@ 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);
}
这就对了,这是为什么啊


这是test2.jsp的内容
<%@ 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>
...全文
86 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
UltraBejing 2008-04-30
  • 打赏
  • 举报
回复
我也想知道,正在找這方面的資料~~~~~
wnba1983 2008-04-24
  • 打赏
  • 举报
回复
如果我的请求要发给一个servlet,点击按钮以后在test.jsp里面显示一个table,数据从servlet传过来,servlet代码要怎么写啊?

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧