Jquery. Post usage sample code

  • 2020-03-30 01:13:20
  • OfStack

Use ajax to verify whether an operation is performed on the front end
For jquery. Post parameters
Url, [data], [callback], [type]

Url: send the request address.

Data: to send Key/value parameter.

Callback: callback function when successfully sent.

Type: returns content format, XML, HTML, script, json, text, _default.
 
$.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:
 
<action name="HhCheckVote" method="checkVote" 
class="org.bkgd.ehome.jeeplugin.userapp.web.action.ActionHhArticleQuery"> 
<result type="json"></result> 
</action> 

The Action
 
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 there must be get,set, and local variables
Method has a return value, not void

Related articles: