Java 如何使用ajax在输入标记上显示数据?
嗨:我想在选择选项时显示输入数据。 我包含了jsp页面,它有输入标记,所以使用ajax将数据发送到包含的jsp页面 这是我的密码。名称为new_order.jspJava 如何使用ajax在输入标记上显示数据?,java,jquery,ajax,jsp,jspinclude,Java,Jquery,Ajax,Jsp,Jspinclude,嗨:我想在选择选项时显示输入数据。 我包含了jsp页面,它有输入标记,所以使用ajax将数据发送到包含的jsp页面 这是我的密码。名称为new_order.jsp <script> $('select#product').change(function() { var param = "code=" + $('#product').val(); $.ajax({ url : 'add_products/add_product
<script>
$('select#product').change(function() {
var param = "code=" + $('#product').val();
$.ajax({
url : 'add_products/add_products.jsp',
contentType : "application/x-www-form-urlencoded; charset=UTF-8",
data : param,
type : 'POST',
dataType : 'html',
success : function(data, textStatus, jqXHR){
}
});
});
...
</script>
<body>
<table class="add_products_tb table" data-toggle="table">
<tr>
..
</tr>
<tr>
..
</tr>
<tr>
<td>
..
</td>
<td>
<table>
<tr>
<td>
<select name="product" id="product" class="selectpicker" data-width="150px">
<option data-hidden="true">-Select-
<%
try {
query = "select * from new_product";
rs = stmt.executeQuery(query);
while (rs.next()) {
product_code = rs.getString("product_code");
%>
<option value="<%= product_code %>"> <%= product_code %>
<%
}
} catch (SQLException e) {
out.println(e);
} finally {
}
%>
</select>
</td>
</tr>
</table>
</td>
<jsp:include page="add_products/add_products.jsp" />
</tr>
</table>
</body>
下一个代码。这包括jsp,add_product.jsp
<script>
$(document).ready(function() {
$('select#product').change(function() {
<%
product_code = request.getParameter("code");
int size = 0;
try {
query = "select * from new_product where product_code='"+product_code+"'";
rs = stmt.executeQuery(query);
while (rs.next()) {
size = rs.getInt("sizes");
%>
$('#size').val("<%= size %>");
<%
}
} catch (SQLException e) {
out.println(e);
} finally {
}
%>
});
});
</script>
...
<body>
<td>
<input type="text" id="size" class="form-control" name="size" />
</td>
<td>
<input type="text" id="color" class="form-control" name="color" />
</td>
<td>
<input type="text" id="price" class="form-control" name="price" value="0" readonly />
</td>
<td>
<input type="text" id="quantity" class="form-control" name="quantity" value="1" />
</td>
<td>
<input type="text" id="total_price" class="form-control" name="total" value="0" readonly />
</td>
</body>
问题是,我想从new_order.jsp接收数据、代码,并在add_product.jsp上显示数据,但它不显示在页面上。我还调试了页面,数据被发送到add_product.jsp,但没有显示在输入上
我将add_product.jsp脚本上的变量product_代码更改为value,而不是jsp变量,而是DB中的特殊值。所以,有数据输入!就一个
我想使用jsp变量显示。请帮帮我…谢谢。您不应该在jsp中包含此java代码。考虑把它移动到servlet或者一些框架,条形等等。谢谢你的评论,但是我不知道servlet。我可以问你什么是框架结构吗?