Use ajax to verify whether an operation is performed on the frontend
The jquery. post parameter is
Url, [data], [callback], [type]
Url: The sending request address.
Data: Key/value parameter to be sent.
Callback: callback function when sending successfully.
Type: The returned content format is xml, html, script, json, text, and _ default.
Copy codeThe Code is as follows:
$. Post ('admin/HhCheckVote. do? Ids = '+' $ {ids} ', {}, function (flag ){
If (flag. isVote = "true "){
Document. getElementById ("jvForm"). action = "admin/HhArticleVoteCommit. do ";
Document. getElementById ("jvForm"). submit ();
} Else {
Alert ("You have voted! ");
}
});
The action configuration in struts. xml is as follows:
Copy codeThe Code is as follows:
<Action name = "HhCheckVote" method = "checkVote"
Class = "org. bkgd. ehome. jeeplugin. userapp. web. action. ActionHhArticleQuery">
<Result type = "json"> </result>
</Action>
Action
Copy codeThe Code is as follows:
Private String isVote;
Public String getIsVote (){
Return isVote;
}
Public void setIsVote (String isVote ){
This. isVote = isVote;
}
Public String checkVote (){
Try {
List <Map <String, Object> list = aloneIMP. checkVote (ids, getCurrentUser (). search (). getResultList ();
If (list. size () = 0 ){
IsVote = "true ";
} Else {
IsVote = "false ";
}
} Catch (SQLException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
Return SUCCESS;
}
PS:
The return value of the action method must be a global variable and must have get, set, or local variables.
The method has a return value. It cannot be void.