我有这个代码片段,我将数据传递到另一个 jsp 文件。
Javascript
$(document).ready(function() {
$("#click").click(function() {
name = $("#name").val();
age = $("#age").val();
$.ajax({
type : "POST",
url : "pageTwo.jsp",
data : "name=" + name + "&age=" + age,
success : function(data) {
$("#response").html(data);
}
});
});
});
HTML
<body>
Name:<input type="text" id="name" name="name">
<br /><br />
Age :<input type="text" id="age" name="age">
<br /><br />
<button id="click">Click Me</button>
<div id="response"></div>
</body>
在pageTwo.jsp中,我的代码是
<%
String name = request.getParameter("name");
String age = request.getParameter("age");
out.println(name + age);
%>
但这不起作用。我的 Jquery 有什么错误吗?有人可以帮助我吗?
最佳答案
$("#click").click(function(e) {
// e.preventDefault();
...
return false;
});
当然还要安装 firebug 或使用 chrome 默认开发工具 (f12)。打开控制台并运行代码。
关于jquery-ui - 使用jquery进行jsp ajax调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14064350/