错误集:js解析jQuery.post返回的xml之Could not find action or result

时间:2022-06-14 05:34:20

js里用jQuery.post去后台查询数据,返回的是xml格式的数据流。

js代码:

var params = "";
params = encodeURI(params);
var url = "frame.query.action";
jQuery.post(url, params, function(xmlHttp){

var items = xmlHttp.getElementsByTagName("jg");
for (var i = 0; i < items.length; i++) {
var x=items[i].childNodes;
var id=x[0].innerHTML;
var name=x[1].innerHTML;
var img=x[2].innerHTML;
if(i==0){
var text1=" <a href='common.jsp'><li style='margin: 0;'><img src='image/tab/"+img+"'><span>"+name+"</span></li>";
$(text1).appendTo($("#ul"));
}else if(i<6){
var text3=" <a href='common.jsp'><li><img src='image/tab/"+img+"'><span>"+name+"</span></li>";
$(text3).appendTo($("#ul"));
}else if(i==6){
var text2=" <a href='common.jsp'><li class='li-first'><img class='img7' src='image/tab/"+img+"'><span>"+name+"</span></li>";
$(text2).appendTo($("#ul"));
}else if(i>6){
var text4=" <a href='common.jsp'><li class='li'><img class='img7' src='image/tab/"+img+"'><span>"+name+"</span></li>";
$(text4).appendTo($("#ul"));
}

}

}, "xml");

用innerHTML获取标签里的值。在搜狗和火狐都是可以完美运行。可是如果换成IE的话就会报下面的错误。

错误信息:

警告: Could not find action or result
There is no Action mapped for namespace [/frame/image/tab] and action name [undefined] associated with context path [/ZKLT_FRAME]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

七月 06, 2016 10:28:29 上午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
严重: Exception occurred during processing request: There is no Action mapped for namespace [/frame/image/tab] and action name [undefined] associated with context path [/ZKLT_FRAME].
There is no Action mapped for namespace [/frame/image/tab] and action name [undefined] associated with context path [/ZKLT_FRAME]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:536)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)

解决的办法是把

var id=x[0].innerHTML;
var name=x[1].innerHTML;
var img=x[2].innerHTML;

替换成:

var id=x[0].firstChild.data;
 var name=x[1].firstChild.data;
var img=x[2].firstChild.data;
用这种方式获取标签里的值。我的判断是IE下用innerHTML取值是取不到。