jquery中使用$.post()进行异步交互时,回调函数不执行??
$(document).ready(function(){//找到三个下拉框varlianmengnameselect=$(".lianmengname").childr...
$(document).ready(function(){
//找到三个下拉框
var lianmengnameselect = $(".lianmengname").children("select");
var fenquselect = $(".fenqu").children("select");
var teamselect = $(".team").children("select");
//为三个下拉框注册事件
lianmengnameselect.change(function(){
alert(1);
//获取当前下拉框的值,如果不为空则传送给服务器
var lianmengnamevalue = $(this).val();
alert(lianmengnamevalue);
//如果为空,那么第二个下拉框要隐藏
if(lianmengnamevalue != ""){
alert("qian");
$.post("chainselect.jsp",{keyword:lianmengnamevalue,type:"top"},function(data){
alert("hou");
if(data.length !=0){
fenquselect.html("");
$("<option value=''>请选择分区</option>").appendTo(fenquselect);
for(var i=0;i<data.length;i++){
$("<option value='" + data[i] + "'>" + data[i] + "</option>").apendTo(fenquselect);
}
fenquselect.parent().show();
}else{
alert("没返回");
}
},"json");
}else{
fenquselect.parent().hide();
}
});
});
为什么,回调函数不执行啊?哪位大哥大姐,帮帮小弟啊??!!不胜感激!!
后台代码:
<%
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
JSONArray array = new JSONArray(); //声明JSON数组
JSONObject objs = new JSONObject();
try {
String param = request.getParameter("keyword");
System.out.println(param);
if (param.equals("west")) {
objs.put("fenquname", "西南赛区");
//array.add(objs);
out.write(objs.toString());
System.out.println(objs.toString());
System.out.println("西部");
} else if(param.equals("east")){
objs.put("fenquname", "东南赛区");
//array.add(objs);
out.write(objs.toString());
System.out.println(objs.toString());
System.out.println("东部");
}
} finally {
//out.close();
}
%>
有错吗?? 展开
//找到三个下拉框
var lianmengnameselect = $(".lianmengname").children("select");
var fenquselect = $(".fenqu").children("select");
var teamselect = $(".team").children("select");
//为三个下拉框注册事件
lianmengnameselect.change(function(){
alert(1);
//获取当前下拉框的值,如果不为空则传送给服务器
var lianmengnamevalue = $(this).val();
alert(lianmengnamevalue);
//如果为空,那么第二个下拉框要隐藏
if(lianmengnamevalue != ""){
alert("qian");
$.post("chainselect.jsp",{keyword:lianmengnamevalue,type:"top"},function(data){
alert("hou");
if(data.length !=0){
fenquselect.html("");
$("<option value=''>请选择分区</option>").appendTo(fenquselect);
for(var i=0;i<data.length;i++){
$("<option value='" + data[i] + "'>" + data[i] + "</option>").apendTo(fenquselect);
}
fenquselect.parent().show();
}else{
alert("没返回");
}
},"json");
}else{
fenquselect.parent().hide();
}
});
});
为什么,回调函数不执行啊?哪位大哥大姐,帮帮小弟啊??!!不胜感激!!
后台代码:
<%
response.setHeader("Cache-Control", "no-cache");
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
JSONArray array = new JSONArray(); //声明JSON数组
JSONObject objs = new JSONObject();
try {
String param = request.getParameter("keyword");
System.out.println(param);
if (param.equals("west")) {
objs.put("fenquname", "西南赛区");
//array.add(objs);
out.write(objs.toString());
System.out.println(objs.toString());
System.out.println("西部");
} else if(param.equals("east")){
objs.put("fenquname", "东南赛区");
//array.add(objs);
out.write(objs.toString());
System.out.println(objs.toString());
System.out.println("东部");
}
} finally {
//out.close();
}
%>
有错吗?? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询