jquery.post用法示例代碼
更新時間:2014年01月03日 16:17:50 作者:
使用ajax在前端驗證是否執(zhí)行某個操作,下面為大家介紹下jquery.post的具體使用
使用ajax在前端驗證是否執(zhí)行某個操作
jquery.post參數(shù)為
url,[data],[callback],[type]
url:發(fā)送請求地址。
data:待發(fā)送 Key/value 參數(shù)。
callback:發(fā)送成功時回調(diào)函數(shù)。
type:返回內(nèi)容格式,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("您已經(jīng)投過票!");
}
});
struts.xml中action配置為:
<action name="HhCheckVote" method="checkVote"
class="org.bkgd.ehome.jeeplugin.userapp.web.action.ActionHhArticleQuery">
<result type="json"></result>
</action>
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:
action 方法的返回值需是全局變量,且必須有g(shù)et,set方法,局部變量則不行
方法有返回值,不能是void
jquery.post參數(shù)為
url,[data],[callback],[type]
url:發(fā)送請求地址。
data:待發(fā)送 Key/value 參數(shù)。
callback:發(fā)送成功時回調(diào)函數(shù)。
type:返回內(nèi)容格式,xml, html, script, json, text, _default。
復(fù)制代碼 代碼如下:
$.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("您已經(jīng)投過票!");
}
});
struts.xml中action配置為:
復(fù)制代碼 代碼如下:
<action name="HhCheckVote" method="checkVote"
class="org.bkgd.ehome.jeeplugin.userapp.web.action.ActionHhArticleQuery">
<result type="json"></result>
</action>
Action
復(fù)制代碼 代碼如下:
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:
action 方法的返回值需是全局變量,且必須有g(shù)et,set方法,局部變量則不行
方法有返回值,不能是void
相關(guān)文章
jQuery調(diào)取jSon數(shù)據(jù)并展示的方法
這篇文章主要介紹了jQuery調(diào)取jSon數(shù)據(jù)并展示的方法,實例分析了jQuery調(diào)用json數(shù)據(jù)及展示的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-01-01
jquery ajaxfileupload異步上傳插件使用詳解
這篇文章主要為大家詳細介紹了jquery ajaxfileupload異步上傳插件的使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02

