日期:2014-05-17 浏览次数:20778 次
<script type="text/javascript">
$(function(){
$("#country").change(function(){
var country = $(this).val();
$.ajax({
url:"/demo",
type:"POST",
dataType:'json',
data:{"country":country},
success:function(data){
alert("data长度: "+$(data).size());
//alert(data);
//$("#city").append("<option>"+"沈阳"+"</option>");
},
error:function(){
alert("数据传输失败!");
}
});
});
});
</script>
String country = request.getParameter("country");
response.setContentType("text;charset=UTF-8");
PrintWriter out = response.getWriter();
JSONObject data = new JSONObject();
data.put("0", "沈阳");
data.put("1", "天津");
data.put("2", "深圳");
data.put("3", "大连");
// String data2 = data.toString();
// JSONObject data = JSONObject.fromObject(data2);
out.print(data);
System.out.println(data.get("0")+" 长度111: "+data.size());
System.out.println("000 "+data);
out.flush();
out.close();