yathirigan
yathirigan

Reputation: 6059

jQuery Ajax Post submitting form multiple times

We have a jsp form, which on a Button Click is submitted to a Struts2 Action Class. From the Action Class, the control flows to a Service (java) class and to a DAO (Java iBatis) class. The DAO class invokes a oracle pl/sql procedure.

Problem:

Reviewing the log statements in Action/Service/DAO & PL/SQL procedure shows that they are being invoked 2/3 times on a single button click. The number of times it executes is quite random, but it's never once (only in code deployed in Staging server).

Strangely, this functionality works fine (invoked only once) when our code is deployed in our Development & Production servers (Websphere 7.1). The exact same code (EAR) when deployed in our Staging server is facing this multiple submit error.

We tried from various browsers (IE 8 & IE 9) and this issue occurs only when we try accessing the application deployed in our staging server.

all our Development, Staging & Production Websphere server is of same version & patch level.

Here is our javascript code used to submit.

 $(document).ready(function() {
                        mask();
                        var config = "${returnedCString}";

                        var f = "${flagS}";

                        if (f == "1"){
                            $.post('<%=request.getContextPath()%>/applyComp'
                                    ,function(data){
                                        unmask();

                                         $("#impactForm").attr('action','<%=request.getContextPath()%>/CompareForm');
                                         $("#impactForm").submit();     

                                    }

                             );
                }
}

The problem is that POST to the following Struts Action is what is happening multiple times

$.post('<%=request.getContextPath()%>/applyComp'

Upvotes: 1

Views: 2082

Answers (1)

coto
coto

Reputation: 2325

Add the submit action in this way:

$('.form_element').unbind('submit').bind('submit',function() {
    // do stuff here...
});

Upvotes: 1

Related Questions