[英]struts2 confirm box with action
I am trying to call struts2 action when I click 'OK' in confirm box. 当我在确认框中单击“确定”时,我试图调用struts2操作。 I have an id from jsp and I want to pass it into the action. 我有一个来自jsp的ID,我想将其传递给操作。 I've tried several ways with no success. 我尝试了几种方法但均未成功。
One thing is using href: 一件事是使用href:
<s:url action="disable" var="urlTag">
<s:param name="id"><s:property value="id"/></s:param>
</s:url>
window.location.href="{urlTag}";
I also tried using ajax 我也尝试过使用ajax
$.ajax( {
type: "POST",
url: "%{urlTag}", //will this declaration of action work?
dataType: "json",
contentType: "application/json; charset=utf-8",
data: "",
success: function() {
alert("success");
}
});
I am new to this and really want to get though it. 我对此很陌生,真的很想解决。 Thank you for any help! 感谢您的任何帮助!
You can achieve it as following. 您可以如下实现。
<s:url id="yourActionId" action="yourAction">
<s:param name="param1" value="param1Value"/>
<s:param name="param2" value="param2Value"/>
</s:url>
<s:a href="%{yourActionId}" onclick = "return confirmBox();"><b>Save</b></s:a>
& your javascript function should be as follows. &您的JavaScript函数应如下所示。
function confirmBox() {
var answer;
answer = window.confirm("Do you really want to perform this action");
if (answer == true) {
return true;
} else {
return false;
}
}
What we have done here is, In s:url tag we have given action to perform with the parameters & given an id to it. 我们在这里所做的是,在s:url标记中,我们给出了要对参数执行的操作并为其指定了ID。 That id is passed to the s:a tag & on click of s:a link we are calling a java script function which will open a confirm box & return true if you press OK & action will be called. 该id传递给s:a标签,并单击s:a链接,我们正在调用一个Java脚本函数,该函数将打开一个确认框,如果您按OK,则返回true,然后将调用操作。 If you press cancel it will return false & action will not be called. 如果按取消,它将返回false并且不会调用操作。 Hope this will help you. 希望这会帮助你。
To make your code work with Struts tags: 使您的代码与Struts标签一起使用:
window.location.href = "<s:property value='%{#urlTag}' />";
and 和
$.ajax( {
type: "POST",
url: "<s:property value='%{#urlTag}' />",
That said, I'm not saying this is what you need. 就是说,我并不是说这就是您需要的。 Are you sure about what you need to do ? 您确定需要做什么吗? GET ? GET? POST ? 发布? An AJAX call, what ? 一个AJAX呼叫,什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.