jquery异步请求返回JSON

页面导航:首页 > 网络编程 > JavaScript > jquery异步请求返回JSON

jquery异步请求返回JSON

来源: 作者: 时间:2016-01-23 10:23 【

第一步:前台的Js Demo:function submitForm(){var hostname = $( " hostname ") val();var port= $( " port ") val();var validName= $( " validName ") val();var vp= $( " vp ") val

第一步:前台的Js Demo:

function submitForm(){
var hostname = $("#hostname").val();
var port= $("#port").val();
var validName= $("#validName").val();
var vp= $("#vp").val();
$.getJSON("req?hostname="+hostname+"&port="+port+"&validName="+validName+"&vp="+vp, function(json){
var iss = json.issuccess //前端解析
if(iss=="S") {
$("#etable").append(""+hostname+""+port+""+validName+""+vp+""+json.validcode+"");
}
});
}

第二步:后端Demo:

@RequestMapping("/main/req")
public String save(){
Date date = new Date();
String hostname = this.request.getParameter("hostname");
String port = this.request.getParameter("port");
String validName = this.request.getParameter("validName");
String vp = this.request.getParameter("vp");
String validcode ="";
validcode = DateFormatUtil.StringFromDate(date);
validcode = Base64.encode(validcode.getBytes());
String savetime = DateFormatUtil.StringFromStanderDate(date);
String id = GUID.getGUID();
Mailconfig mailconfig = new Mailconfig();
mailconfig.setId(id);
mailconfig.setHostname(hostname);
mailconfig.setPort(port);
mailconfig.setSavetime(savetime);
mailconfig.setValidCode(validcode);
mailconfig.setValidName(validName);
mailconfig.setVp(vp);
boolean res = mailService.save(mailconfig);
Map returnMsg = new HashMap();
try {
if(res == true){
returnMsg.put("issuccess", "S");
returnMsg.put("validcode", validcode);
this.response.getWriter().print(JSONObject.fromObject(returnMsg));
}else {
returnMsg.put("issuccess", "E");
this.response.getWriter().print(JSONObject.fromObject(returnMsg));

}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

Tags:

相关文章

    文章评论

    最 近 更 新
    热 点 排 行
    Js与CSS工具
    代码转换工具
    
    <