我有脚本代码:

<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;

    }


我的动作支持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接口。

最佳答案

只需尝试从更改javascript方法

xmlHttp.onreadystatechange=stateChangedmp();




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

07-26 05:25