$(document).ready(function(){ getJsonServicecontent(); }); function getJsonServicecontent(){ $.post ( '<%=basePath%>/itemgrade/servicestandardAction!queryJsonServicecontent.action?s='+new Date(), { servicelevelid: function(){return $("#servicelevelid").val();} }, function(data) //回调函数 { $("#servicecontentid").empty(); $("#servicecontentid").append($("<option/>").text("请选择").attr("value","")); $(data).each(function () { var nametemp=this.name; if(nametemp.length>4){ nametemp=nametemp.substring(0,4)+"..."; } $("#servicecontentid").append($("<option title="+this.name+" />").text(nametemp).attr("value",this.id)); $("#servicecontentid").val('${servicecontentid}'); }); }, "json" //返回类型 ); }
<div class="lbsz_content_022" >
<div class="bddh_content_01" style="padding-left:0px; font-size: 14px;">项目考评管理 < <strong><span style="color:#fa7917;">服务标准管理</span></strong></div>
<div class="tj_content_211">
<table width="744" border="0" cellspacing="0" cellpadding="0" height="50" align="left">
<tr>
<td width="123" style="color:#333" > 服务标准名称</td>
<td width="168">
<input name="queryname" value="${queryname}" type="text" class="chaxun_shurukuang" id="queryname" />
</td>
<td width="78">
服务等级
</td>
<td width="103">
<select id="servicelevelid" name="servicelevelid" οnchange="getJsonServicecontent()">
<option value="">请选择</option>
<c:forEach items="${cachemap.servicelevel}" var="servicelevel">
<option value="${servicelevel.key}" <c:if test='${servicelevel.key==servicelevelid}'>selected="selected"</c:if>>${servicelevel.value}</option>
</c:forEach>
</select>
</td>
<td width="78">
服务内容
</td>
<td width="103">
<select id="servicecontentid" name="servicecontentid" style="width: 90px;">
</select>
</td>
<td width="73"><a href="javascript:void(0)" οnclick="queryfun();"><img src="<%=basePath%>images/ny_chaxun.jpg" width="65" height="28" /></a> </td>
<td width="19"></td>
<td width="180" style="color:#333"> </td>
</tr>
</table>
</div>
/**
* 根据服务等级查询服务内容
* @return
*/
public String queryJsonServicecontent(){
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
String servicelevelid=null;
if(request.getParameter("servicelevelid")!=null&&!request.getParameter("servicelevelid").equals("")){
servicelevelid=request.getParameter("servicelevelid");
}
String jsonRoad=itemgradeService.queryJsonServicecontent(servicelevelid);
try {
PrintWriter out = response.getWriter();
out.print(jsonRoad);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public String queryJsonServicecontent(String servicelevelid) {
JSONArray jsonArray = new JSONArray();
List<Servicecontent> servicecontentList=itemgradeDAO.queryJsonServicecontent(servicelevelid);
for(Servicecontent s:servicecontentList){
JSONObject jsonobject = new JSONObject();
try {
jsonobject.put("id",s.getCode());
jsonobject.put("name", s.getName());
jsonArray.put(jsonobject);
} catch (JSONException e) {
e.printStackTrace();
}
}
return jsonArray.toString();
}
public List<Servicecontent> queryJsonServicecontent(String servicelevelid){
return getSqlSession().selectList("itemgrade.queryJsonServicecontent",servicelevelid);
}
<select id="queryJsonServicecontent" resultType="net.hlj.procomplaints.bean.Servicecontent" parameterType="java.lang.String" > select * from TBDIC_SERVICECONTENT where servicelevelid=#{servicelevelid,jdbcType=VARCHAR} </select>