0

I am very new to ajax,I want to make an ajax call from my jsp page to servlet and then display a data in table on the same page.When i make an ajax call url path goes to servlet but status shows error in call back function.I think i unable to set data type in ajax call,Please tell me the flow and where i did mistake in ajax call,For all help thanks in advance.

Here my code is:

var postData = $('#ajaxform').serializeArray();
$
.ajax({
     type: 'POST',
    url : "attendancePercentage",
    data : postData,
    dataType:'html',
    success : function(data, status) {
        alert(status);
        alert(data);
    }
});

servlet :Here in console i get the data in s.o.p statement,but ajax call not success.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


    String stDate=request.getParameter("startDateValue");
    String enDate=request.getParameter("endDateValue");
    System.out.println(""+stDate+""+enDate+"");
    List stList = new ArrayList();

    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/test_schema", "root", "root");
        String sql = "select * from attendance where attendance.date>=? and attendance.date<=?";

        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, stDate);
        pstmt.setString(2, enDate);

        rs = pstmt.executeQuery();
        while (rs.next()) {
            StudentMark ge = new StudentMark();

            ge.setStudentName(rs.getString(3));
            ge.setDate(rs.getString(2));
            ge.setStatus(rs.getString(4));

            stList.add(ge);
      }
      System.out.println("list>>"+stList);

    } catch (Exception e) {
        System.err.println(e.getMessage());
    }



}

0 Answers0