我已經使用jquery驗證來檢查部門名稱已經存在於特定的組織中。但它沒有返回正確的結果。請有人幫助我。jquery驗證錯誤,同時檢查部門名稱
這裏是我的Jquery:
$(document).ready(function(){
var validator = $("#frmAddDepartment").validate({
errorElement:'div',
rules: {
organization:{
required:true
},
department: {
required: true,
allowChars:true,
//remote:$('#site_url').val()+"admin/department/check_department/"+$('#department').val()+"/"+$('#Organization').val(),
checkdeptname:true
}
},
messages: {
organization:{
required:languageArray['select_organization']
},
department:{
required:languageArray['enter_department'],
//remote:jQuery.format(languageArray['dept_exist'])
}
}
});
jQuery.validator.addMethod("allowChars", function(value, element) {
var filter = new RegExp(/[^a-zA-Z0-9\-& ]/);
if(!(filter.test(value)))
{
return true;
}else
return false;
},languageArray['please_enter_valid_chars']);
jQuery.validator.addMethod("checkdeptname", function(value, element) {
returnResult = false;
$.ajax({
url: $('#site_url').val()+"admin/department/check_department",
type: "GET",
data:{department:value,organization:$('#Organization').val()},
success: function (result)
{
returnResult = result;
alert(returnResult);
}
});
//$.get($('#site_url').val()+"admin/department/check_department", { department:value,organization:$('#Organization').val() }, function(data){alert(data);returnResult = result;});
return returnResult;
},languageArray['dept_exist']);});
PHP控制器的功能:
public function check_department()
{
$sql_query=$this->department_model->check_department();
if($sql_query>0)
{
echo "false";
}else
{
echo "true";
}
}
allowFrenchChars是自定義方法嗎?和它的定義在哪裏? – 2013-09-25 06:59:52
很高興發佈相關信息的相關錯誤或結果視圖 –
@ user1978104我已經添加了allowFrenchChar方法。我已將其重命名爲允許使用。但那不是問題。我通過AJAX檢查部門名稱時得到不正確的結果。 –