zoukankan      html  css  js  c++  java
  • Ajax实现页面跳转与结果返回

    ajax实现页面局部跳转与结果返回

    1、带有结果返回的提交过程

    这里用一个提交按钮来演示,HTML代码为:

    <input type="button" class="btn" value="提报" name="submit4" onClick="tibao();">

    点击提报按钮后,通过ajax来实现跳转到action中处理,JavaScript代码为:

    function tibao(){
    var id='';
    var
    URL = <select:link page="/smokeplan.do?method=Tibao&idset="/>+id; $.ajax({url: URL,   type: 'GET',   success: function(result) { alert(result); } });
    }

    action处理完成后,将返回的结果放到result中,在页面弹出提示信息;当然这里的action跳转是需要配置xml的。

    后台Java类处理过程为:

    //提报
            public void Tibao(ActionMapping mapping, ActionForm form,
                    HttpServletRequest request, HttpServletResponse response) throws Exception {
                String idset=request.getParameter("idset");
                CallHelper helper = initializeCallHelper("L_SmokeBoxtibaoWLDan", form,request, false);
                helper.setParam("bill_ids",idset);
                helper.setParam("personid",getPersonId(request));
                helper.execute();
                PrintWriter write = response.getWriter();
                write.print(helper.getOutput("message"));
                write.close();
            }

    这里是通过一个sql语句对数据进行处理,返回一个message,并将信息打印到页面;

    这里做的操作的结果是反映到response对应的位置,于是拿到属于response的流,而不是new一个出来。

    也就是说我从那里跳转过来的,我这个信息就会返回到那里去。所以在js中就可以用result进行接收这个返回结果,并且用alert提示。

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    Ext JS 6学习文档-第5章-表格组件(grid)
    Ext JS 6学习文档-第4章-数据包
    Ext JS 6学习文档-第3章-基础组件
    Ext JS 6学习文档–第2章–核心概念
    Ext JS 6学习文档–第1章–ExtJS入门指南
    Console命令详解,让调试js代码变得更简单
    使用Node.js+Socket.IO搭建WebSocket实时应用
    node.js应用--转载
    Node.js 究竟是什么?
    Hello, Unity!
  • 原文地址:https://www.cnblogs.com/sdgf/p/4753929.html
Copyright © 2011-2022 走看看