Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous call issue

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.

like image 489
Will Mcavoy Avatar asked Jun 20 '26 19:06

Will Mcavoy


1 Answers

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.

like image 193
MaVRoSCy Avatar answered Jun 22 '26 10:06

MaVRoSCy