In my JSP (index.jsp), I am submitting a form that passes the Parameters to another JSP (action.jsp) using JSON.
<form id="form">
<input type="text" name="name"/>
<input type="button" id="btn" value="OK"/>
</form>
And here is the Jquery Code of index.jsp :
$(document).ready(function(){
$("#btn").click(function(){
var name = $("input[name=name]").val();
$.ajax({
cache:false,
url:"action.jsp",
data:{name:name},
contentType:"application/json; charset=utf-8",
dataType:"json",
success:function (msg) {
alert("SUCCESS");
// here I want a String that is
// generated(generatedString) in action.jsp.
});
}
},
error:function () {
alert("Unable to add.");
}
});
});
});
My action.jsp code :
<%
String name = request.getParameter("name");
String generatedString = "E5142";
response.setContentType("application/json");
out.print(generatedString);
%>
The form is submitted to action.jsp successfully but cannot get the value 'generatedString' in index.jsp in return.
UPDATED: index.jsp always showing error in alert : "Unable to add." Tried what is said in comments, but didn't come up with success message.