首先Action很简单,就是成功后跳转到另外页面
action配置为 Struts.xml:
- XML code
<package name="bs" namespace="" extends="struts-default"> <action name="PostList" class="org.erif.action.PostListAction"> <result name="success">/BBS/postlist.jsp</result> </action> </package>
通过s:form表单可以正常转到,如下:
- HTML code
<s:form action="PostList.action" > <s:textfield name="type"></s:textfield> <s:submit></s:submit> </s:form>
现在我就想用 $.post('PostList.action'); 替换s:form
- HTML code
$('#btnList').click(function() { alert("tips"); //方式一: //$.post('PostList.action'); //方式二: $.ajax({ url : 'PostList.action', type : 'post' , dataType : 'text', //data : params, success : function(){ alert("OK"); }, error : function(XmlHttpRequest, textStatus, errorThrown) { alert(XmlHttpRequest.status); if (XmlHttpRequest.status == 200) { var errorstr = XmlHttpRequest.responseText; alert(errorstr); } } }); });
方式一没有反应,方式二会alert("OK"),然后也停在当前页面;
弱弱的问下怎样用jquery的方式写才能跟s:form的效果一样正常跳转呢???
------解决方案--------------------
你要在客户端进行跳转,服务端跳转客户端无法处理的。
- JScript code
$.ajax({ url : 'PostList.action', type : 'post' , dataType : 'text', //data : params, success : function(){ alert("OK"); window.location='/BBS/postlist.jsp'////////// }, error : function(XmlHttpRequest, textStatus, errorThrown) { alert(XmlHttpRequest.status); if (XmlHttpRequest.status == 200) { var errorstr = XmlHttpRequest.responseText; alert(errorstr); } } });