strut2跟ajax整合,返回的结果是整个网页??
struts2.1 跟ajax整合,可是返回的responseText却是整个网页??
下面给出配置:
js_ajax:
function creatXML(){
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
else if(window.ActiveXObject){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
function search(){
creatXML();
var url;
var input=document.getElementById("search-text").value;
xmlHttp.open("POST","Chonghai_ajax",true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange=display;
xmlHttp.send("name="+input);
}
function display(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
var xmlDoc=xmlHttp.responseText;
alert(xmlDoc); ;
}
}
else{
}
}
stuct.xml
<action name="*_ajax" class="com.zhku.action.{1}_ajax" >
<result name="success" type="stream">
<param name="contentType">text/html</param>
<param name="inputName">result</param>
</result>
</action>
[解决办法]
你的请求没有进入到struts2的action中,将请求路径后面加上.action
[解决办法]