Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
jQuery.validator.addMethod("mail", function (value, element) {
var f = 0;
jQuery.ajax({
type: "get",
url: "Master/chkmail",
async: true,
cache: false,
data: { mail: function () { return $("#email").val(); } },
dataType: "json",
success: function (data) { if (data == true) { f = 1; } else { f = 0; }
},
error: function () { alert(arguments[1]); }
})
return f < 0 ? false : true;
});

Mastercontroller:
public JsonResult chkmail(string mail)
{
JsonResult result = new JsonResult();
BLL.Member bll = bll = new MvcBBS.BLL.Member();
if (bll.emailExists(mail))
{

result.Data = true;
}
else
{
result.Data = false;
}
return result;
}
Please help me,thanks a lot
Posted
Comments
Christian Graus 16-Dec-12 20:39pm    
why do you use jQuery. instead of $. ? It makes your code hard to read compared to the accepted norm
Sergey Alexandrovich Kryukov 6-Mar-13 15:23pm    
Please stop posting non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

1 solution

data: { mail: function () { return $("#email").val(); } },

Does this even work ? Why not get the value and put it in to the data in another line of code ?

Have you debugged in Chrome ? What line has the error ?
 
Share this answer
 
Comments
gavinv 16-Dec-12 20:52pm    
the chkmail can get the value from that code, i've checked it. I just test this in
IE9.The problem is when i run this set of code it just show me that "email" already exsited, maybe this prove that "success" can't get the json from "chkmail"
gavinv 16-Dec-12 21:01pm    
The validate code is :
$(document).ready(function () {
$("#regf").validate({
rules: {

username: { required: true
},
email:{required:true,email:true,mail:true},
password: { required: true }
},
messages: {
username: { required: '  input it!' },
email: { required: '  please input!', email: '  like this:a@a.com!', mail: '  already exsited!' },
password: { required: 'pealse input!' }
}
}

)
})

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900