为什么这个程序中的所在城市无法显示出来
html代码
所在省份:<s:select list="#provinceBean.selectAll()" name="province" listKey="id" listValue="name" id="province"></s:select><p>
所在城市:
jquery代码
var p = $('#province').val();
$('#province').change(function(){
p = $('#province').val();
$.ajax({
type:"post",
url:"findCities.jsp",
data:"id="+p,
dataType:"json",
success:function(data){ 
      var cities = $('<select>'); 
      if(data){
      for(var i=0;i<data.length;i++){
      cities.html("<option value = '"+data[i].cityCode+"'>"+data[i].cityName + "</option");
      }
      $('#province').after(cities);
      } 
}
});
});
jsp代码
String pid = request.getParameter("id");
     if(pid == null){
     pid = "34";
     }
     int id = Integer.parseInt(pid);
     String sql = "select * from city where city.province="+id;
     ResultSet rs = stmt.executeQuery(sql);
    StringBuffer selectJSON = new StringBuffer("[");
       while(rs.next()){
       selectJSON .append("{'cityCode':'") .append(rs.getInt(1)). append("', 'cityName':'"). append(rs.getString(2)) .append("'},");
       }
  selectJSON.deleteCharAt(selectJSON.length() - 1);AjaxJSPjquery

解决方案 »

  1.   

    sql 语句查出来有没有结果啊
      

  2.   

    jsp和html都在一个页面吧,你的json数据没经过response.getWriter().println('json字符串')。
      

  3.   

    有结果 [{'cityCode':'1', 'cityName':'北京'}] 
      

  4.   

    是在最后加上response.getWriter().println(selectJSON);吗
      

  5.   

    是在最后加上response.getWriter().println(selectJSON);吗是的,不然你的ajax是获取不到的。
      

  6.   

    是在最后加上response.getWriter().println(selectJSON);吗是的,不然你的ajax是获取不到的。
    还是不行啊