Ext.Ajax.request获取后台的数据

    xiaoxiao2023-03-24  6

           尝试用Ext.Ajax异步操作来改变页面回显的值,试了好几次都没成功,终于啊,试出来试出来了,功夫不负有心人。(开心)

    具体如下:

        js代码:

    <script type="text/javascript"> Ext.onReady(function(){ var djzcqh = Ext.getCmp('djzcqh').getValue(); Ext.Ajax.request({ url: '<%=ctxPath%>/lr/areaAction.do?method=getDjzcqhName', //url携带参数 params:{ djzcqh:djzcqh }, success: function(response){ //获取后台response写入的值 var data =response.responseText; Ext.getCmp('assistant3').setValue(data); } }); }); </script>

        后台代码(struts1):

    public ActionForward getDjzcqhName(final ActionMapping mapping, final ActionForm actionForm, final HttpServletRequest request, final HttpServletResponse response) throws IOException { String djzcqh = request.getParameter("djzcqh"); response.setCharacterEncoding("UTF-8"); String djzcqhName =bs.getDjzcqh(djzcqh); //将要回显的值写出去 response.getWriter().write(djzcqhName); return null; }         总体描述一下,当Jsp页面加载完执行JS通过ajax异步请求url,后台方法执行完成后,将值通过response写出去,请求完成后,执行成功函数,通过response.responseText就可以获得后台写出去的值,然后就可以随便操作该数据了。

    转载请注明原文地址: https://ju.6miu.com/read-1202847.html
    最新回复(0)