今天学习jQuery是用到了$.post()这个函数 网上的教程用的是asp的 而我用的是java来弄的 附上代码
jsp页面是
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
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>My JSP 'jqueryParent.jsp' starting page</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 type="text/javascript" src="jquery/jquery-2.1.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button#button2").click()(function(){
$.post("demo_post.jsp",{name:"Lucky",city:"Lodon"},function(data,status){
alert("数据:"+data+"内容"+status);
});
});
});
</script>
</head>
<body>
<button id="button2">向页面发送http post请求</button>
</body>
</html>
使用到的demo_post.jsp是
<%
String name=request.getParameter("name");
String city=request.getParameter("city");
out.print(name+city);
%>
但是打开tomcat后点击按钮应该会弹出对类似这样的对话框
但是完全没反应 求大神问题究竟在哪里