jquery - How to return JSON data from servlet and get that from the success call back function of ajax call -
i trying return json data servlet , access data success call function of ajax call. here js code:
$(document).ready(function() { $("#submit").on("click", function() { userid = $("#usernametxt").val(); seqans = $("#seqanstxt").val(); seqques = $("#seqques").val(); command = $("#_cmd").val() $.ajax({ type : "post", datatype : "json", url : "/inventory/invcontroller", data : {_cmd : command, uid : userid, ques : seqques, ans : seqans}, success : function(retval) { if(true) { $("#resetpwd").show(); } }, error: function(error) { console.log(error); } }); }); });
here serrvlet code:
boolean issuccess = loghelper.performforgotpwdvalidation(agentdetails); printwriter out = null; jsonobject jsonobj = new jsonobject(); try { jsonobj.addproperty("isvalid", issuccess); response.setcontenttype( "application/json" ); response.setcharacterencoding("utf-8"); out = response.getwriter(); out.write(jsonobj.tostring()); out.flush(); } catch (ioexception e) { e.printstacktrace(); } { if( null != out ) { out.close(); } }
i trying return "issuccess" json data. how should return that. please let me know how return data in success call function of ajax call.
thanks in advance.
Comments
Post a Comment