gpt4 book ai didi

java - Ajax 函数始终返回 0 并且不会继续进行

转载 作者:行者123 更新时间:2023-11-30 11:36:13 27 4
gpt4 key购买 nike

我有脚本代码:

<script type="text/javascript" >

var xmlHttp=null;
function GetXmlHttpObject()
{

try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function popSubCategory(){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return;
}



var url="<%= request.getContextPath()%>/populatePropertySubCategory.action";
alert(url);


xmlHttp.onreadystatechange=stateChangedmp();
xmlHttp.open("POST",url,true);
xmlHttp.send(null);
}
function stateChangedmp(){

alert("Hello "+xmlHttp.readyState);
if(xmlHttp.readyState==4)
alert("lk"+xmlHttp.responseText);
}
</script>

我的Action方法是

public String populatePropertySubCategory() {
System.out.println("sub property called " );

String errorXml = "This is a Sample to Check";

response.setContentType("text/html");
response.setHeader("Cache-Control", "no-cache");
try {
response.getWriter().write(errorXml);
} catch (IOException ioe) {
ioe.printStackTrace();
}

return SUCCESS;

}

我的 Action 支持xml是

 <action name="populatePropertySubCategory" method="populatePropertySubCategory" class="PropActionSupport">
<interceptor-ref name="validation">
<param name="excludeMethods">populatePropertySubCategory</param>
</interceptor-ref>
<result name="success" type="tiles" >
submitProperty
</result>
</action>

现在,当我调用此代码时,仅警告 0 并且不打印响应文本。

我已经实现了 ServletResonseAware 接口(interface)。

最佳答案

只需尝试从

更改 javascript 方法
xmlHttp.onreadystatechange=stateChangedmp();  

xmlHttp.onreadystatechange=function myFun {stateChangedmp();}

关于java - Ajax 函数始终返回 0 并且不会继续进行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14621903/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com