i am sending 2 data to the servlet through ajax from jsp and the servlet just get those data, then convert to json obj and return that json. now the jsp get that json to show those 2 data. ajax is successfully executing the servlet but everytime is alerts me the error not the success. pls tell me what should i do to display those data in alert? details.jsp:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
function doajax(){
$.ajax({
url: "AccountDetails",
type: "post",
dataType: "json",
data: { "mobileNo":"01914752849", "fullName":"Md. Muzahid-ul Islam" },
error:function(){
alert("error occured!!!");
},
success:function(data){
alert(data.fullName + "
" + data.mobileNo);
}
});
}
</script>
账户 Details.java( 服务器) :
PrintWriter out = response.getWriter();
try {
String fullName = request.getParameter("fullName");
String mobileNo = request.getParameter("mobileNo");
JSONObject jsonObject = new JSONObject();
jsonObject.put("fullName", fullName);
jsonObject.put("mobileNo", mobileNo);
out.println(jsonObject);
} finally {
out.flush();
out.close();
}