5 Replies Latest reply on Jan 21, 2011 7:07 AM by Murali Krishna

    How to cancel an Ajax request?

    Chris Lowe Apprentice

      In RF 3.0.1 I was able to cancel an ajax request by returning false from the JavaScript function called from onsubmit. The following code snippet calls confirmChangeLoss() which returns true to proceed with the ajax call or false if it should be ignored. In RF 3.1.0, this is no longer works - if I return false, the ajax call happens ayway. Should it be working? Or is there now a different mechanism for canceling requests?

      Best Regards,


      <h:selectOneMenu value="#{permissionsHome.selectedGroup}" required="true" >
       <a4j:support event="onchange" action="#{permissionsHome.onChangeGroup}" onsubmit="confirmChangeLoss()" oncomplete="resetChanged()" reRender="grd-permission"/>
       <s:selectItems value="#{groups}" var="group" label="#{group.description}" />
       <s:convertEntity />
      The corresponding JavaScript
      var stateModified = false;
      function confirmChangeLoss() {
       var result = true;
       if (stateModified) {
       result = confirm('Lose unsaved changes?');
       return result;

        • 2. Re: How to cancel an Ajax request?
          Chris Lowe Apprentice

          Thanks for looking at this, I've added my vote the the case.



          • 3. Re: How to cancel an Ajax request?
            Ilya Shaikovsky Master

            I'll cancel the bug. We both have made the same mistake from the begining :)

             <h:inputText value="#{bean.property}">
             <a4j:support event="onkeyup" reRender="test"
             onsubmit="if (confirm('Lose unsaved changes?')) {return false;}">
             <h:outputText value="#{bean.property}" id="test"></h:outputText>

            This code works. So you should add this additional "if" statement to check what was returned from function.

            • 4. Re: How to cancel an Ajax request?
              Chris Lowe Apprentice

              D'oh - you're right! Sorry to have wasted your time.


              • 5. Re: How to cancel an Ajax request?
                Murali Krishna Newbie

                Hi llya,


                I am using richfaces-ui-3.3.2.GA.jar and facing strange scenario... I have JSF code just like below



                <a4j:form ajaxSubmit="true" >                    
                    <h:inputText id="seekIndex" size="1" maxlength="3" value="#{searchVo.index}">
                        <a4j:support event="onkeyup" action="goto" 
                             onsubmit="if (event.keyCode != 13) { return false; }else if(!navigateAway()){ return false; } "
                    </h:inputText> of #{searchVo.count}


                It works fine with the context name like 'myproject'. if context name has some special characters(-)  like 'myproject-test' this throws 404 error when it submits ajax request.



                <form id="j_id98" name="j_id98" method="post" 
                'actionUrl':'/myproject/x2Dtest/spring/myInformation?execution=e1s1'}%20)" target="">
                <input type="text" id="j_id98:seekIndex" name="j_id98:seekIndex" value="1" maxlength="3" onkeyup="if (event.keyCode != 13) { return false; }else if(!navigateAway()){ return false; } ;
                A4J.AJAX.Submit('j_id98',event,{'similarityGroupingId':'j_id98:j_id99','parameters':{'j_id98:j_id99':'j_id98:j_id99'} ,
                'actionUrl':'/myproject\x2Dtest/spring/myInformation?execution=e1s1'} )" size="1" autocomplete="off"> of 5<input type="hidden" autocomplete="off" name="j_id98" value="j_id98"><input type="hidden" autocomplete="off" name="autoScroll" value="">
                <script type="text/javascript">
                function clear_j_id98() {
                function clearFormHiddenParams_j_id98(){clear_j_id98();}
                function clearFormHiddenParams_j_id98(){clear_j_id98();}
                </script><script type="text/javascript">//<![CDATA[
                </script><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="e1s1" autocomplete="off"></form>



                '/myproject/x2Dtest/spring/myInformation?execution=e1s1'  obviously this is encoded wrongly.


                plz help me how resolve this??