欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jQuery異步驗證用戶名是否存在示例代碼

 更新時間:2014年05月21日 16:26:21   作者:  
有個需求就是異步驗證用戶名是否存在。用的技術(shù)是jQuery異步驗證和struts2,大家可以參考下
現(xiàn)在有個需求就是異步驗證用戶名是否存在。用的技術(shù)是jQuery異步驗證和struts2(其實springMVC也是一樣的道理,都只是一個控制器).

表單:
復制代碼 代碼如下:

<input class="width150" maxlength="32" type="text" id="dept_name" name="dept.dept_name"
value="${dept.dept_name}" onchange="tocheckname()"/>

js代碼:
復制代碼 代碼如下:

function tocheckname()
{
var deptName= $("#dept_name").val();
$.ajax({
type:"POST",
cache:false,
url : "${rootPath}/dept/checkdeptname.htm",
dataType : "text",
data:{"dept.id":"${dept.id}","dept.dept_name":deptName},
async:false,
success : function(data){
if(0<parseInt(data)){
alert("此科室已存在");
$("#dept_name").attr("value","");
$("#dept_name").focus();
}
}
});
}

后臺的代碼:
復制代碼 代碼如下:

/**
* 根據(jù)科室名稱查詢是否存在此科室
*
* @return
* @throws Exception
*/
public String checkdeptname() throws Exception {
if (UtilAPI.isNull(dept)) {
dept = new Dept();
}
int count = this.deptService.checkdeptname(dept.getId(), dept.getDept_name()); //如果存在返回1,不存在返回0
try {
response.getOutputStream().print(count);
}
catch (IOException e) {
e.printStackTrace();
}
return Action.NONE;
}

相關(guān)文章

最新評論