How to return a boolean value from a Java class to ajax? -
i want homecoming boolean
value java class ajax request. value passed ajax java method can't homecoming boolean
value ajax. getting error: unknown homecoming value type
.
@requestmapping(value="/availability", method=requestmethod.post) public boolean emailavailability(string email) { boolean = true; query q = new query("userdetailsnew"); preparedquery pq = ds.prepare(q); system.out.println("email in availability : " + email); (entity e : pq.asiterable()) { string email = (string) e.getproperty("email"); if (email.equals(email)) { = false; homecoming a; } } homecoming a; }
my ajax code :
var email = $("#email").val(); $.ajax({ method:"post", url:"/availability", datatype: 'json', data:{ email: json.stringify(email) }, success : function (data){ console.log(data); if(!data){ $("#email").focusout(function(){ $('#submit').prop('disabled',true); $('.status').html("email taken..."); }); } else { $('.status').html("email available..."); $('#submit').prop('disabled',false); } } });
hi can utilize the jsonresponse class doing this.here @responsebody annotation takes care of result type.please refer docs more info.
@requestmapping(value="/availability", method=requestmethod.post) public @responsebody jsonresponse emailavailability(string email) { jsonresponse res = new jsonresponse(); boolean = true; query q = new query("userdetailsnew"); preparedquery pq = ds.prepare(q); system.out.println("email in availability : " + email); (entity e : pq.asiterable()) { string email = (string) e.getproperty("email"); if (email.equals(email)) { = false; homecoming a; } } res.setstatus("success"); res.setresult(a); homecoming res; }
in ajax can verify using
success: function(response){ // have response if(response.status == "success"){ //your code }
please seek once.hope helps you.
java ajax json spring
No comments:
Post a Comment