联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 网页前端技术 > 正文

jquery.post用法示例代码 - Web前端

作者:98wpeu发布时间:2026-10-08分类:网页前端技术浏览:7


导读:使用Ajax在前端验证是否执行某个操作JQuery.post参数为url,[data],[callback],[type]url:发送请求地址。data:待发送Key/v...
使用Ajax在前端验证是否执行某个操作
JQuery.post参数为
url,[data],[callback],[type]

url:发送请求地址。

data:待发送 Key/value 参数。

callback:发送成功时回调函数。

type:返回内容格式,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("您已经投过票!");
}
});

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 方法的返回值需是全局变量,且必须有get,set方法,局部变量则不行
方法有返回值,不能是void

标签:示例代码Webpostjquery


网页前端技术排行
最近发表
网站分类
标签列表