sdgf

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提示。

 

 

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

分类:

技术点:

相关文章:

  • 2021-07-04
  • 2022-12-23
  • 2021-06-17
  • 2021-11-17
  • 2021-11-19
  • 2021-10-21
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2021-10-01
  • 2021-11-20
  • 2021-11-07
  • 2021-10-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案