页面上异步接收数据形成select

js代码:

document.getElementById("subcategory").options.length = 0;
		  $.getJSON("categoryList.do",function(data) {
		  $("<option value=''>--请选择--</option>").appendTo("#subcategory");
		  var i = 0;
		  $.each(data, function(i) {
		     $("<option value='" + data[i].id + "'>"+ data[i].name + "</option>").appendTo("#subcategory");
		  });
		});

catagoryList.do中的代码:

public String doExecute(ParameterParser paramParser, Context context,
			Navigator nav) {
		int pid = paramParser.getInt("pid");
		List<BackCategory> bl = backCategoryService.queryListByPid(pid);
		String bjson = JackSonUtil.getJson(bl);
		System.out.println(bjson);
		PrintWriter out = null;
		try {
			out = response.getWriter();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if(out != null){
			out.print(bjson);
			out.flush();
			out.close();
		}
		return SUCCESS;
	}



你可能感兴趣的:(页面上异步接收数据形成select)