我尝试使用jquery验证插件验证表单。我正在尝试在表格中是否有emailId,如果不允许注册则不是。 但是,它显示json对象总是大于零。我尝试使用getjson,它在localhost中不起作用。那么,我哪里错了?
的login.jsp
$('input#emailId').blur( function() {
$.ajax({
url:'/getUserByEmailOrPhone-'+$('#emailId').val()+'-'+$('#contactNumber').val(),
type:'GET',
data: 'json',
success:function(json){
if (json.length == 0)
{
$('.email-check').append('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true" id="tt2" clientidmode="Static" runat="server" Visible="False"></span>');
}
else{
alert('user exists');
$('.email-check').append('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true" id="tt2" clientidmode="Static" runat="server" Visible="False"></span>');
}
}
});
});
AppController.java
@RequestMapping(value={"/getUserByEmailOrPhone-{emailId}-{contactNumber}"}, method = RequestMethod.GET)
public @ResponseBody User getUserByEmailOrPhone(@PathVariable("contactNumber") String contactNumber,
@PathVariable("emailId") String emailId,ModelMap model){
return service.getUserByEmailOrPhone(emailId, contactNumber);
}
答案 0 :(得分:0)
如果json变量包含正确的值,那么您可以执行as-
成功:函数(JSON)
{
if(json === undefined)
{
//你的行动
} ...