解决Jquery下拉框数据动态获取的问题

2020-05-23 06:22:52易采站长站整理

废话不多说,直接上源码:

select.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%>" rel="external nofollow" >

<title>My JSP 'select.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" rel="external nofollow" >
-->
<script type="text/javascript" src="js/jquery-2.1.1.min.js" charset="utf-8"></script>
<script type="text/javascript">

function get_app_type() {

$.ajax({
type: "post",
url: "AppTypeShow.action", //获取json数据
dataType: "json",
success: function(data) {
var d = eval("(" + data + ")");
for(var i = 0; i < d.length; i++) {
var id = d[i].id;
var name = d[i].name;
var opt = "<option value='" + id + "'>" + name + "</option>";
$("#appType").append(opt);
}
},
error: function() {
alert("系统异常,请稍后再试!")
}
});

}

function get_app_class() {

$.ajax({
type: "post",
url: "AppClassShow.action",
dataType: "json",
success: function(data) {
var d = eval("(" + data + ")");
for(var i = 0; i < d.length; i++) {
var id = d[i].id;
var name = d[i].name;
var opt = "<option value='" + id + "'>" + name + "</option>";
$("#appClass").append(opt);
}
},
error: function() {
alert("系统异常,请稍后再试!")
}
});

}

$(document).ready(function() {

get_app_type();
get_app_class();

});
</script>
</head>

<body>
<table>
<tr>
<td align="right">APP类型:</td>
<td align="left">
<select name="appType" id="appType"
style="margin-left: 16px; height: 30px; width: 110px; text-align: left; size: 3; color: #505050;">
<option value="-1">---请选择---</option>
</select>
</td>
</tr>
<tr height="25px"><td> </td></tr>
<tr>
<td align="right">APP种类:</td>
<td align="left">
<select name="appClass" id="appClass"
style="margin-left: 16px; height: 30px; width: 110px; text-align: left; size: 3; color: #505050;">