struts2中jquery无刷新怎么接受后台boolean值
$.ajax({type:"POST",url:"pageTest.action!abc",data:"userName="+$("#userName").val()+"...
$.ajax( {
type:"POST",
url:"pageTest.action!abc",
data:"userName="+$("#userName").val()+"&passWord="
+ $("#passWord").val(),
success:function(msg) {
//alert(msg);
}
});
以这种格式向后台传输数据,action中如何传一个boolean值过来呢!
我在success中的操作是局部刷新的吗? 展开
type:"POST",
url:"pageTest.action!abc",
data:"userName="+$("#userName").val()+"&passWord="
+ $("#passWord").val(),
success:function(msg) {
//alert(msg);
}
});
以这种格式向后台传输数据,action中如何传一个boolean值过来呢!
我在success中的操作是局部刷新的吗? 展开
4个回答
展开全部
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter pw = response.getWriter();
int num = 0;
boolean flag = false; if(flag)num=0;else num=1;
pw.write(num);
pw.flush();
<action name="pageTest" class="pageTestAction" method="abc">
<result name="success">
/jsp/card/inventory/testString.jsp
</result>
</action>
testString.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="GBK"%>
这个页面就这个,什么都不要。
然后你再alert()试试?
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter pw = response.getWriter();
int num = 0;
boolean flag = false; if(flag)num=0;else num=1;
pw.write(num);
pw.flush();
<action name="pageTest" class="pageTestAction" method="abc">
<result name="success">
/jsp/card/inventory/testString.jsp
</result>
</action>
testString.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="GBK"%>
这个页面就这个,什么都不要。
然后你再alert()试试?
展开全部
返回json数据就行
<action name="pageTest" class="pageTestAction" method="abc">
<result type="json">
<param name="includeProperties">action里的boolean变量名</param>
</result>
</action>
然后jquery读json
<action name="pageTest" class="pageTestAction" method="abc">
<result type="json">
<param name="includeProperties">action里的boolean变量名</param>
</result>
</action>
然后jquery读json
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询