加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于如何接受异步ajax请求返回前台的数据

发布时间:2020-12-16 03:35:32 所属栏目:百科 来源:网络整理
导读:1、第一种方式通过bean,后台需封装成json数据格式,前台paseJSON(); public void checkCode() { ResponseMessage rm = new ResponseMessage(true,null); String hql = "from TblWrPeople t where t.wrPeopleCode='"+code+"' and t.delFlag='"+Constants.DEL

1、第一种方式通过bean,后台需封装成json数据格式,前台paseJSON();

public void checkCode() {

ResponseMessage rm = new ResponseMessage(true,null);

String hql = "from TblWrPeople t where t.wrPeopleCode='"+code+"' and t.delFlag='"+Constants.DELFLAGA+"'";

List<TblWrPeople> tblWrPeopleList = (List<TblWrPeople>)this.workResService.find(hql);

if (tblWrPeopleList != null && tblWrPeopleList.size() > 0) {

rm.setSuccess(false);

rm.setErrorMsg("数据库中已存在该代号,请重新录入");

this.responseAJAX(JSONObject.fromObject(rm).toString(),getResponse());

}

}

前台获取:

function checkCode() {

var code = $("#wrPeopleCode").val();

$.post('workRes_checkCode.action',{"code":code},function(result){

result = $.parseJSON(result);

if (result.success == false){

alert(result.errorMsg);

$("#wrPeopleCode").val('');

}

});

}

2、后台直接返回一个String类型的字符串,前台的话不再需要parseJSON,直接获取result即可;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读