json格式的Ajax提交示例代码
网络编程 2021-07-05 10:37www.168986.cn编程入门
这篇文章主要介绍了json格式的Ajax提交,需要引入一些jar包及js包,示例代码如下
需要加入.springsource..apache.mons.logging-1.1.1.jar、.json.jar和jquery-1.10.0.min.js包
<form class="form-inline"> 扫码: <input id="txtQRCode" type="text"> <button id="btnReceive">确定</button> </form> <script type="text/javascript"> //扫描二维码 $('#btnReceive').click(function(){ $.ajax({ type:"GET", url:"<%=basePath%>asynchronous/receive.do", data:{qrCode:$('#txtQRCode').val()}, dataType:"json", cache:false, suess:function(msg){ //var json = eval('('+msg+')');//拼接的json串 var flag = msg.flag; var info = msg.info; if(flag){ alert(info); $('#txtQRCode').val(""); } else{ alert(info); } }, error:function(error){alert(error);} }); }); }); </script> package .utcsoft.pcapps.selfservice.controller; import java.io.IOException; import java.io.PrintWriter; import java..UnknownHostException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import .apache.mons.logging.Log; import .apache.mons.logging.LogFactory; import .json.JSONException; import .json.JSONObject; import .springframework.stereotype.Controller; import .springframework.web.bind.annotation.RequestMapping; import .utcsoft.mon.attributes.YesNoEnum; import .utcsoft.mon.util.DateOperate; import .utcsoft.pcapps.selfservice.attributes.KeyRequestAttr; import .utcsoft.pcapps.selfservice.dao.FlowDao; import .utcsoft.pcapps.selfservice.dao.KeyRequestDao; import .utcsoft.pcapps.selfservice.entity.Flow; import .utcsoft.pcapps.selfservice.entity.KeyRequest; import .utcsoft.pcapps.selfservice.entity.UtcUsers; @Controller @RequestMapping(value = "/asynchronous") public class AsynchronousController { private final static Log logger = LogFactory.getLog(AsynchronousController.class); / 扫描二维码 将订单改为UTC审核 @param request @param response @throws IOException @throws JSONException / @RequestMapping(value="/receive") public void receive(HttpServletRequest request,HttpServletResponse response) throws IOException, JSONException{ String rets = ""; boolean b = false; try{ String qrcode = request.getParameter("qrCode")==null?"":request.getParameter("qrCode").toString().trim(); logger.info(qrcode); if(!"".equals(qrcode)){ JSONObject obj = new JSONObject(qrcode); String orderid = obj.getString("orderid").trim(); if(!"".equals(orderid)){ KeyRequestDao keyDao = new KeyRequestDao(); KeyRequest k = new KeyRequest();//综合信息 k = keyDao.findOneByOrderId(orderid); if(k!=null){ //修改订单状态为审核 int n = keyDao.updateState(orderid, String.valueOf(KeyRequestAttr.KqStateEnum.verify.getStep())); Flow flow = new Flow(); FlowDao flowDao = new FlowDao(); UtcUsers users = (UtcUsers)request.getSession().getAttribute("utcUsers"); //将记录插入Flwo表中 flow.setKq_id(orderid); flow.setKq_state(String.valueOf(KeyRequestAttr.KqStateEnum.cus_send.getStep())); flow.setKq_state_to(String.valueOf(KeyRequestAttr.KqStateEnum.verify.getStep())); flow.setIs_Pass(YesNoEnum.Y.getCode()); flow.setUser_id(users.getUser_id()); flow.setUser_id_from(users.getUser_id()); flow.setOpTimer(DateOperate.getDateTime()); int flowNum = flowDao.save(flow); logger.info("扫描二维码提交结果n="+n+";flowNum="+flowNum); if(n>0){ b = true; rets = "UTC接收订单成功"; logger.info("UTC接收订单成功"); } else{ rets = "UTC接收订单失败"; logger.info("UTC接收订单失败"); } } else{ rets = "订单查询失败"; logger.info("订单查询失败"); } } else{ rets = "二维码中订单号为空"; logger.error("二维码中订单号为空"); } } else{ rets = "二维码内容为空"; logger.error("二维码内容为空"); } } catch(Exception e){ e.printStackTrace(); rets = e.getMessage(); logger.error(e.getMessage()); } JSONObject ret = new JSONObject(); ret.put("flag", b); ret.put("info", rets); PrintWriter write = response.getWriter(); write.write(ret.toString()); write.flush(); } }
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程