First, my class relationships
Entity class:
Class entityclass {
Private int ID;
}
Class model extends entityclass {
Private string username;
Private string password;
}
Then in the action
Class modelaction extends actionsupport {
Private Boolean success;
Private model;
// The get method is required to return the JSP page as a JSON object.
// Get method ,,,,
}
Action configuration file:
<Package name = "model" namespace = "/"
Extends = "JSON-Default">
<Action name = "delete_action" class = "modelaction"
Method = "delete">
<Result name = "delete" type = "JSON">
<! -- Set the data to be returned, such as GetModel, getsuccess, and other get methods in the action. You can use the root attribute to set the sequence. -->
<Param name = "root"> success </param>
<! -- Includeproperties: this parameter directly returns the JSON data of the object. The foreground does not require eval conversion. <Param name = "root"> result </param> is different. The foreground needs eval conversion. -->
<! -- <Param name = "includeproperties"> success </param> -->
<! -- Ignorehierarchy parameter: indicates whether the hierarchy is missing or not, that is, the inheritance relationship,
For example, if testaction is inherited from baseaction, the returned JSON string in testaction does not include the attribute value of the parent class baseaction,
The default value of ignorehierarchy is true. If it is set to false, attributes of the parent class and subclass are returned together.
If this attribute is set to false, IDs in entityclass are also serialized. Otherwise, IDs are not serialized.
-->
<Param name = "ignorehierarchy"> false </param>
<! -- Remove some attributes in the model, which are generally not used together with the includeproperties attribute -->
<! -- <Param name = "excludeproperties"> id </param> -->
</Result>
<Result name = "error" type = "JSON"> </result>
</Action>
JSON objects received on the JSP page:
Function postconnect (){
VaR request = false;
Try {
Request = new XMLHttpRequest ();
} Catch (trymicrosoft ){
Try {
Request = new activexobject ("msxml2.xmlhttp ");
} Catch (othermicrosoft ){
Try {
Request = new activexobject ("Microsoft. XMLHTTP ");
} Catch (failed ){
Request = false;
}
}
}
If (! Request ){
Alert ("error initializing XMLHttpRequest! ");
Return false;
}
Return request;
}
Function booleancheck (ID ){
VaR request = postconnect ();
If (! Request ){
Alert ("Access failed ");
}
VaR url = "<% = request. getcontextpath () %>/delete_action? Id = "+ ID;
Request. Open ("get", URL, true );
Request. onreadystatechange = function (){
If (request. readystate = 4 ){
If (request. Status >=200 & request. Status <300) | request. Status = 304 ){
VaR OBJ = eval ('+ request. responsetext + '); // The two above if statements must be added; otherwise, the eval method returns multiple data records (including error data ). Request. responsetext is the returned JSON object.
If (OBJ ){
$ ("Tr [ID = '" + ID + "']"). Remove (); // refresh the list here
} Else {
Alert ("deletion failed! ");
}
}
Else {
Alert ("request was unsuccessful:" + request. status );
}
}
};
Request. Send (null );
}