文本框中失去焦点时从界面中传值到action中与数据库中的值比较后返回给页面...

界面(jsp):

$(function() {

//失去焦点后跟数据库查询
  $("#t_id").blur(function() {   //失去焦点
                $.ajax({ 
                    type: "post",                  
                    url: "${pageContext.request.contextPath}/taskmanage!query.action",  
                    data: {'t_id' : $('#t_id').val()},            
                    dataType: "json",  
                    success: function(msg) {
                    alert(msg.tid);
                                $('#t_id_msg').html(msg.tid);
    
                    }
                }); 
               
               
            });
  
 });

 

 

        <input type="text" name="t_id"  id="t_id" />
           <span  id="t_id_msg"></span>

 

action中:

//新增任务时查询任务id是否存在

private Map<String,String> info = new HashMap<String,String>();


 public void query() {
  try {
   info = (Map<String, String>) this.daoHelper.getSqlMapClientTemplate().queryForObject("taskmanageMap.info", this);
   if (null != info) {
    JSONObject json = new JSONObject();
    json.put("tid", "此id已存在");
    response.getWriter().print(json);
   } else {
    JSONObject json = new JSONObject();
    json.put("tid", "可以用此id");
    response.getWriter().print(json);
   }

  } catch (Exception e) {
   e.printStackTrace();
  }

 }
 

数据库中:

select  T_ID          as     "t_id"
  from TASK where t_id=#t_id#

转载于:https://my.oschina.net/meSpace/blog/40924

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值