0

I am trying to develop a struts 2 web application and sending data via Ajax but the console show an 500 (Internal Server Error). I have tried a log but no solution found. But the operation performed successfully in back end means my data is updated but the output is Internal Server Error Here is my code..

ajax function

   function revertIbcData(mydata) {
            var paNo = $(mydata).attr("rollNo");
            var viNo = $(mydata).attr("idNo");
            alert(paNo + " " + viNo);

            $.ajax({
                type: 'GET',
                contentType: 'application/json;  charset=utf-8',
                dataType: "json",
                url: "revert.do",
                data: {rollNo: paNo, idNo: viNo},
                success: function (data) {
                    alert(data.msg);
                },
                error: function (abc, cba, errorThrown) {
                    alert('Error: ' + errorThrown);
                }
            });
        }

action code

    public String revertData() {
    try {
        conn = connect.getConnection();
        ibcDAO.revertIbcProcessDetail(conn, rollNo, idNo);
        msg = "Detail of " + rollNo + " and " + idNo + " reverted successfully.";
        System.out.println(msg);
        return "success";
    } catch (Exception e) {
        e.printStackTrace();
        return "success";
    } 
}

and struts.xml is

    <action name="revert"  class="pac.ProcessAction" method="revertData">
        <result name="success" type="json"></result>                   
    </action>      
Justin
  • 3
  • 2
  • 1
    Have you looked at the server logs? There is most likely a log message (hopefully with a stack trace) that says what went wrong. Note that the 500 response code comes from the server, so something **on the server side** should know what the problem is. – Stephen C Dec 20 '16 at 07:53
  • did you try to stringify the request data? – Bindrid Dec 20 '16 at 08:36
  • @Bindrid: yes i have tired stringify but getting same result.. – Justin Dec 20 '16 at 08:40

2 Answers2

0

Set log inside revertData to determine where error occurs, and check this article: http://tech.learnerandtutor.com/read-json-object-from-struts-2-action-by-jquery-ajax/

mystdeim
  • 4,802
  • 11
  • 49
  • 77
0

Try this:

<action name="revert"  class="pac.ProcessAction" method="revertData">
       <result name="success" type="json">
         <param name="root">jsonString</param>
       </result>                   
    </action>   

Here "jsonString" should be a class level variable.

Nabarun Dey
  • 104
  • 9