json格式中Ajax提交的示例分析

這篇文章給大家分享的是有關(guān)json格式中Ajax提交的示例分析的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。

創(chuàng)新互聯(lián)專注于瑪沁網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供瑪沁營(yíng)銷型網(wǎng)站建設(shè),瑪沁網(wǎng)站制作、瑪沁網(wǎng)頁(yè)設(shè)計(jì)、瑪沁網(wǎng)站官網(wǎng)定制、小程序定制開發(fā)服務(wù),打造瑪沁網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供瑪沁網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

需要加入:com.springsource.org.apache.commons.logging-1.1.1.jar、org.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, 
success: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 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); 

/** 
* 掃描二維碼 將訂單改為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){ 
//修改訂單狀態(tài)為審核 
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("掃描二維碼提交結(jié)果: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 = "二維碼中訂單號(hào)為空"; 
logger.error("二維碼中訂單號(hào)為空"); 
} 
} 
else{ 
rets = "二維碼內(nèi)容為空"; 
logger.error("二維碼內(nèi)容為空"); 
} 

} 
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(); 
} 
}

感謝各位的閱讀!關(guān)于“json格式中Ajax提交的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

網(wǎng)站題目:json格式中Ajax提交的示例分析
文章URL:http://muchs.cn/article24/gedoce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供虛擬主機(jī)、網(wǎng)站營(yíng)銷、關(guān)鍵詞優(yōu)化、網(wǎng)站排名靜態(tài)網(wǎng)站、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)