Get the App
SLTechnology News&Howtos  ›  Development  › 

Sample Analysis of Ajax submission in json format

Shulou Source: shulou.com Published: 2022-06-03 19:49:06 11月12日 Update

This article shares with you the content of the sample analysis submitted by Ajax in json format. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Need to join: com.springsource.org.apache.commons.logging-1.1.1.jar, org.json.jar and jquery-1.10.0.min.js packages

Scan the code: confirm / / scan the QR code $('# btnReceive') .click (function () {$.ajax ({type: "GET", url: "asynchronous/receive.do", data: {qrCode:$ ('# txtQRCode'). Val ()}, dataType: "json", cache:false, success:function (msg) {/ / var json = eval ('('+ msg+')'); / / stitched json string var flag = msg.flag; var info = msg.info If (flag) {alert (info); $('# txtQRCode'). Val ("");} else {alert (info);}}, error:function (error) {alert (error);}}); package com.utcsoft.pcapps.selfservice.controller; import java.io.IOException; import java.io.PrintWriter; import java.net.UnknownHostException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log Import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.json.JSONObject; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.utcsoft.common.attributes.YesNoEnum; import com.utcsoft.common.util.DateOperate; import com.utcsoft.pcapps.selfservice.attributes.KeyRequestAttr; import com.utcsoft.pcapps.selfservice.dao.FlowDao; import com.utcsoft.pcapps.selfservice.dao.KeyRequestDao; import com.utcsoft.pcapps.selfservice.entity.Flow Import com.utcsoft.pcapps.selfservice.entity.KeyRequest; import com.utcsoft.pcapps.selfservice.entity.UtcUsers; @ Controller @ RequestMapping (value = "/ asynchronous") public class AsynchronousController {private final static Log logger = LogFactory.getLog (AsynchronousController.class) / * * scan the QR code to change the order to UTC audit * @ 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 (); / / Comprehensive information k = keyDao.findOneByOrderId (orderid); if (kits null) {/ / modify the order status to audit 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"); / / insert records into the Flwo table 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 ("scan QR code submission result: n =" + n + "; flowNum=" + flowNum); if (n > 0) {b = true; rets = "UTC received order successfully"; logger.info ("UTC received order successfully");} else {rets = "UTC failed to receive order"; logger.info ("UTC failed to receive order") } else {rets = "order query failed"; logger.info ("order query failed");} else {rets = "order number in QR code is empty"; logger.error ("order number in QR code is empty");} else {rets = "QR code content is empty"; logger.error ("QR code content is empty");} 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 ();}} Thank you for reading! This is the end of this article on "sample Analysis submitted by Ajax in json format". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Order QR code content format example analysis success more article order number query good practical information article status look knowledge result Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology Xiaomi Huawei Docker