Please check the following
In your struts.xml edit the following
<result name="success" type="json">
<param name="ignoreHierarchy">false</param>
<param name="includeProperties">
actionErrors.*,
actionMessages.*,
fieldErrors.*
</param>
</result>
And in your js code edit the below.
var actionErrs= (data.actionErrors); // list of action errors
var actionMsgs= (data.actionMessages); // list of action messages
var actionFldErrs= (data.fieldErrors); // list of field errors
var alertMessage="";
var i=0;
for(i=0;i<actionErrs.length; i++){
alertMessage=alertMessage+" "+actionMessages[i];
}
alert(alertMessage);
Edit
in your JSP instead of the following,
<s:if test="hasActionErrors()">
<s:actionerror />
</s:if>
use
<div id="err"></div>
and add below line in you js code
document.getElementById("err").innerHTML=alertMessage;
to check the result name
if your method signature like below,
public String getJsonData(){
if(....){
return ERROR;
}
return SUCCESS
}
You can get the data in your js code as below,
var actionErrs= (data.actionErrors); // list of action errors
var actionMsgs= (data.actionMessages); // list of action messages
var actionFldErrs= (data.fieldErrors); // list of field errors
var resultName=(data.getJsonData); // get The method return value
var alertMessage="";
var i=0;
for(i=0;i<actionErrs.length; i++){
alertMessage=alertMessage+" "+actionMessages[i];
}
alert(alertMessage);