Use Ajax to verify that an action is performed on the front end
Jquery.post parameter is
Url,[data],[callback],[type]
URL: Sends the request address.
Data: Key/value parameter to be sent.
Callback: callback function when sending success.
Type: Returns the content format, XML, HTML, script, JSON, text, _default.
Copy Code code 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've already voted!") ");
}
});
The action in Struts.xml is configured as:
Copy Code code as follows:
<action name= "Hhcheckvote" method= "Checkvote"
class= "Org.bkgd.ehome.jeeplugin.userapp.web.action.ActionHhArticleQuery" >
<result type= "JSON" ></result>
</action>
Action
Copy Code code 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 needs to be a global variable and must have a Get,set method, and the local variable is not
Method has a return value and cannot be void