1
我試圖驗證表單使用jQuery驗證插件。我試着是否在表中有emailId,如果不允許註冊,否則不。 但是,它顯示json對象總是大於零。我嘗試使用getjson,它不適用於本地主機。那麼,我哪裏錯了?如何檢查json對象是否爲null?
的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);
}
'console.log(json)'in'success'並檢查你得到了什麼? –
我在控制檯中得到了整個jsp代碼。 –
您的Java服務器可以正常工作嗎? – SalDev