3

I am facing thread issue in my application follow are the summary of the issue

: root cause of the code

document.strikeoffForm.submit();
window.open('<%= baseURL %>/jsps/makeStrikeOffs/Print.jsp', "printStrikeoff");

its happening because of Asynchronous call. the issue is I am doing like this,

  1. submitting form

  2. opening new window to show the submitted value.

But some time before submiting a form the 2 action happened beacuse of Asynchronous call.

All I want is how can I order things as once first call is finished than only second call of window open should happen. Because of this issue the window doesn't get proper values.

I think the solution in Ajax but I am not aware how to do.

Cœur
  • 32,421
  • 21
  • 173
  • 232
Will Mcavoy
  • 495
  • 4
  • 22

2 Answers2

2

This is very easy with a little JQuery and a little bit of AJAX. Try the code below:

    $.ajax({
        type: 'POST',
        url: 'pageToSubmitTo.jsp',
        data: {
            $("#idOfYourForm").serialize()
        },
        beforeSend:function(){
            // this is where we append a loading image
        },
        success:function(data){
            // successful request; 
            window.open('jsps/makeStrikeOffs/Print.jsp', "printStrikeoff");
        },
        error:function(){
            // failed request; give feedback to user
        }
    });

For this to work you have to include the JQuery library to your code.

Community
  • 1
  • 1
MaVRoSCy
  • 16,907
  • 14
  • 76
  • 116
0

Hi All thanks for your all inputs. It may be the not proper way but for as of now its working fine so its good to me.. I given solution like this:

document.strikeoffForm.submit();           
<%  Thread.sleep(500)%>        
window.open('<%= baseURL %>/jsps/makeStrikeOffs/Print.jsp', "printStrikeoff");      
Will Mcavoy
  • 495
  • 4
  • 22