Click here to Skip to main content
12,064,941 members (39,797 online)
Rate this:
 
Please Sign up or sign in to 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 16-Dec-12 15:17pm
gavinv421
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
   
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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 ?
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160204.4 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100