求筒子们一起看看这是什么问题。。纠结我好久了。我在一个jsp页面上放了一个doubleselect 显示省和市,数据是在一个action里面初始化的。
然后自己写了个js方法,当城市选项改变时触发:
//城市id改变,触发
$(function(){
var cityobj=document.getElementById("maps_cityid");
var provinceobj=document.getElementById("maps_provinceid");
cityobj.onchange=function(){
var cityId=cityobj.value;
var chexingId = chexingobj.value;
//alert(cityId+","+chexingId);
getDataByParams(cityId,chexingId);
}
}); function getDataByParams(cityId,chexingId){
var url="ajax/shangjialist.action";
var data={cityid:cityId,
chexingid:chexingId};
$.post(url,data,callback,"text");
} function callback(text){
alert(text);
}
异步请求到另一个aciton类里面,处理ajax的方法关键代码如下:HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/xml;charset=utf-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter(); String msg = "these data from server.";
out.print(msg);
out.flush();
out.close();
发送和接受数据都没问题,页面也没报错,但是myeclipse console报错了:
2011-5-20 10:56:49 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
tag 'doubleselect', field 'list', name 'provinceid': The requested list key 'provinceVOs' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location] 为什么ajax返回数据到jsp页面后,页面没报错,后台会报错呢?很奇怪诶。求大家讨论讨论吧。
然后自己写了个js方法,当城市选项改变时触发:
//城市id改变,触发
$(function(){
var cityobj=document.getElementById("maps_cityid");
var provinceobj=document.getElementById("maps_provinceid");
cityobj.onchange=function(){
var cityId=cityobj.value;
var chexingId = chexingobj.value;
//alert(cityId+","+chexingId);
getDataByParams(cityId,chexingId);
}
}); function getDataByParams(cityId,chexingId){
var url="ajax/shangjialist.action";
var data={cityid:cityId,
chexingid:chexingId};
$.post(url,data,callback,"text");
} function callback(text){
alert(text);
}
异步请求到另一个aciton类里面,处理ajax的方法关键代码如下:HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/xml;charset=utf-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter(); String msg = "these data from server.";
out.print(msg);
out.flush();
out.close();
发送和接受数据都没问题,页面也没报错,但是myeclipse console报错了:
2011-5-20 10:56:49 org.apache.catalina.core.ApplicationDispatcher invoke
严重: Servlet.service() for servlet jsp threw exception
tag 'doubleselect', field 'list', name 'provinceid': The requested list key 'provinceVOs' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location] 为什么ajax返回数据到jsp页面后,页面没报错,后台会报错呢?很奇怪诶。求大家讨论讨论吧。
var data={cityid:cityId,chexingid:chexingId};这个键值对某个对应不上吧 还有一种可能根据翻译是这个Map列字段无法用iterator(小推车)遍历 可能是json格式错误?对了 data发过去的格式{cityid:cityId,chexingid:chexingId};是叫Json不?作为一个资深的菜鸟发了这么多字 目的只有一个"打酱油!" 结尾加上几个字"求高手解决!"
感谢这哥们肯花时间看我这么烂的代码。
贴出来的代码被我删减了几行,chexingId是另一个下拉菜单的值 。应该还是不妨碍分析。经过测试,异步调用和返回都没问题。
数据返回后,跟页面上的struts2的标签 有冲突 出现了问题