六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 35|回复: 0

jquery 与prototype 中ajax的应用

[复制链接]

升级  15.33%

17

主题

17

主题

17

主题

秀才

Rank: 2

积分
73
 楼主| 发表于 2013-1-29 10:35:51 | 显示全部楼层 |阅读模式
jquery ajax校验
   /**************jquery ajax校验***************************************************/function onclickXml(name){                   var hotelId=$("#hotelId").val();     if(name.value ==''||name.value.length==0){alert('输入的用户名为空!'); return false; }     else     {     alert("aaaaa");         $.ajax({           type: "POST",           url: "<%=request.getContextPath()%>/hotelManage.do?method=ajaxValidateName",           data: "uname="+name.value,           success: function(msg){         alert(msg);             }        });      }      }

prototype ajax校验
/**************prototype ajax校验***************************************************/ function validateName(name){     var   url="<%=request.getContextPath()%>/hotelManage.do?method=ajaxValidateName";   var pars="hotelId="+encodeURI(encodeURI($("#hotelId").val()))+"&name="+encodeURI(encodeURI(name.value));//解决中文乱码问题        var myAjax = new Ajax.Request(        url,        {        method: 'post',        parameters: pars,        onComplete: showResponse        });  }function showResponse(originalRequest){  // var tt = originalRequest.responseText;   alert(originalRequest.responseText); // $("#loading").html("<font color='red'>该名称已存在!</font>");   //  $("#loading").show(); }

jsp代码
<input type="hidden" name="hotelId" id="hotelId" value="<c:out value='${hotelId}'/>"/>  名称:<input name="name" id="name" value="" type="text" size="16" /><!--onclickXml(this) -->

后台action
public ActionForward ajaxValidateName(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) throws Exception{HotelBusIface service = (HotelBusIface) this.getObject();String name = URLDecoder.decode(request.getParameter("name"),"UTF-8");String hotelId = request.getParameter("hotelId");PrintWriter out = response.getWriter();System.out.println(name+"-----"+hotelId);if(service.existImageName(hotelId, name)){System.out.println("exist");out.println("exist");}else{System.out.println("noexist");out.println("noexist");}        return  null;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表