I'm using iFrame class JSP page with Date picker field on it. On selecting a date from the picker, I'm sending the date to the Struts Action using jQuery AJAX call like below:
$( "#datepickerStart" ).datepicker({
onSelect: function(dateText, instance) {//date select from picker to trigger
$.ajax({
type: "Post",// post method
url: 'checkAvailability.do?operation=getlist&datepickerStart='+ ("#datepickerStart").val(), // passing URL with date value to STRUTS Action
data: "date="+date,
//dataType: "application/json",
success: function(data) {
alert(data); //getting with the complete HTML page
}
});
}
});
And from DB I'm fetching the results in LIST and converting to JSON object like below:
Gson gson = new Gson();// Using google GSON to convert to JSON
String json = new Gson().toJson(lRList);
response.setContentType("application/json");// setting content type
response.setCharacterEncoding("UTF-8"); //setting character encoder
response.getWriter().write(json);// writing to response the JSON object
System.out.println("JSON Object::"+json);
And in standard output gives me the result like this:
JSON Object::[{"bookDate":"2014-07-11","fromTime":"2:00PM","totime":"3:30PM","userID":"XXX","isSuccess":false},
{"bookDate":"2014-07-11","fromTime":"10:30AM","totime":"11:00AM","userID":"XXX","isSuccess":false}]
But the alert in Ajax success gives the complete HTML page :(. I need this data and want to populate the values in the same JSP by showing in a div table. So can anyone help me on this to resolve it and let me know where I'm doing the mistake...