I have a link from parent window which opens a child window. On clicking the save button in child window, i want to call an struts action and close the child window. And then reload the parent window.
function closeChildWindow(){
document.forms[0].action="/rms/action/linkSourceList";
document.forms[0].submit();
var originalSource = document.getElementById("originalSource").value;
opener.location.href = '../action/editSource?source_id='+originalSource;
}
I used the above code in child window. This code reload the parent window, but not calling the action from the child window. Can anyone suggest me the solution?? Thanks in advance... :)
Things would be much easier if you used some JavaScript library.
I will give an example in jQuery:
function submitAndCloseChildWindow(){
var data = /* get form data here */;
$.ajax({
url: "/rms/action/linkSourceList",
data: data,
method: "POST"
}).done(function() {
opener.location.href = '../action/editSource?source_id=' + $("#originalSource").val();
window.close();
});
}
This will keep your window open on failure and allow you to handle any expected errors. Also, consult the console if the request still does not get through.