How to display success message after ajax form summit












1















I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks



<script type="text/javascript">
//<![CDATA[
var formId = 'product_sendtofriend_form';
var sendfriendForm = new VarienForm(formId, false);
var postUrl = '<?php echo $this->getSendUrl() ?>';
function doAjax() {
if (sendfriendForm.validator.validate()) {
new Ajax.Updater(
{ success:'formSuccess' }, postUrl, {
method:'post',
asynchronous:true,
evalScripts:false,
onComplete:function(request, json) {
Element.hide(formId);
Element.show('formSuccess');
},
onLoading:function(request, json){
Element.show('formLoader');
},
parameters: $(formId).serialize(true),
}
);
}
}

new Event.observe(formId, 'submit', function(e){
e.stop();
doAjax();
});
//]]>
</script>









share|improve this question














bumped to the homepage by Community 8 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    1















    I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks



    <script type="text/javascript">
    //<![CDATA[
    var formId = 'product_sendtofriend_form';
    var sendfriendForm = new VarienForm(formId, false);
    var postUrl = '<?php echo $this->getSendUrl() ?>';
    function doAjax() {
    if (sendfriendForm.validator.validate()) {
    new Ajax.Updater(
    { success:'formSuccess' }, postUrl, {
    method:'post',
    asynchronous:true,
    evalScripts:false,
    onComplete:function(request, json) {
    Element.hide(formId);
    Element.show('formSuccess');
    },
    onLoading:function(request, json){
    Element.show('formLoader');
    },
    parameters: $(formId).serialize(true),
    }
    );
    }
    }

    new Event.observe(formId, 'submit', function(e){
    e.stop();
    doAjax();
    });
    //]]>
    </script>









    share|improve this question














    bumped to the homepage by Community 8 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      1












      1








      1


      2






      I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks



      <script type="text/javascript">
      //<![CDATA[
      var formId = 'product_sendtofriend_form';
      var sendfriendForm = new VarienForm(formId, false);
      var postUrl = '<?php echo $this->getSendUrl() ?>';
      function doAjax() {
      if (sendfriendForm.validator.validate()) {
      new Ajax.Updater(
      { success:'formSuccess' }, postUrl, {
      method:'post',
      asynchronous:true,
      evalScripts:false,
      onComplete:function(request, json) {
      Element.hide(formId);
      Element.show('formSuccess');
      },
      onLoading:function(request, json){
      Element.show('formLoader');
      },
      parameters: $(formId).serialize(true),
      }
      );
      }
      }

      new Event.observe(formId, 'submit', function(e){
      e.stop();
      doAjax();
      });
      //]]>
      </script>









      share|improve this question














      I've been working on this code I found somewhere. I use it to submit the Send to Friend form from a popup. It works but I can't get it to display the success message after it submits the form. Right now after it submits the form it just disappears. Maybe someone good at ajax can see what's the matter with it. Thanks



      <script type="text/javascript">
      //<![CDATA[
      var formId = 'product_sendtofriend_form';
      var sendfriendForm = new VarienForm(formId, false);
      var postUrl = '<?php echo $this->getSendUrl() ?>';
      function doAjax() {
      if (sendfriendForm.validator.validate()) {
      new Ajax.Updater(
      { success:'formSuccess' }, postUrl, {
      method:'post',
      asynchronous:true,
      evalScripts:false,
      onComplete:function(request, json) {
      Element.hide(formId);
      Element.show('formSuccess');
      },
      onLoading:function(request, json){
      Element.show('formLoader');
      },
      parameters: $(formId).serialize(true),
      }
      );
      }
      }

      new Event.observe(formId, 'submit', function(e){
      e.stop();
      doAjax();
      });
      //]]>
      </script>






      magento-1.9 ajax forms






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 13 '16 at 15:57









      FreejoyFreejoy

      444924




      444924





      bumped to the homepage by Community 8 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 8 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          2 Answers
          2






          active

          oldest

          votes


















          0














          Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess'); to Element.show('formSuccess2'); and added the div like this <div id="formSuccess2" style="display:none">hello</div>



          <script type="text/javascript">
          //<![CDATA[
          var formId = 'product_sendtofriend_form';
          var sendfriendForm = new VarienForm(formId, false);
          var postUrl = '<?php echo $this->getSendUrl() ?>';
          function doAjax() {
          if (sendfriendForm.validator.validate()) {
          new Ajax.Updater(
          { success:'formSuccess' }, postUrl, {
          method:'post',
          asynchronous:true,
          evalScripts:false,
          onComplete:function(request, json) {
          Element.hide(formId);
          Element.show('formSuccess2');
          },
          onLoading:function(request, json){
          Element.show('formLoader');
          },
          parameters: $(formId).serialize(true),
          }
          );
          }
          }

          new Event.observe(formId, 'submit', function(e){
          e.stop();
          doAjax();
          });
          //]]>
          </script>





          share|improve this answer































            0














            Change code



            onComplete:function(request, json) {
            Element.hide(formId);
            Element.show('formSuccess');
            }


            to:



            onComplete:function(request, json) {                            
            $('formSuccess').show();
            }





            share|improve this answer


























            • It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

              – Freejoy
              Apr 13 '16 at 18:48











            • updated answer check it

              – Prashant Valanda
              Apr 13 '16 at 20:07











            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "479"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f110781%2fhow-to-display-success-message-after-ajax-form-summit%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess'); to Element.show('formSuccess2'); and added the div like this <div id="formSuccess2" style="display:none">hello</div>



            <script type="text/javascript">
            //<![CDATA[
            var formId = 'product_sendtofriend_form';
            var sendfriendForm = new VarienForm(formId, false);
            var postUrl = '<?php echo $this->getSendUrl() ?>';
            function doAjax() {
            if (sendfriendForm.validator.validate()) {
            new Ajax.Updater(
            { success:'formSuccess' }, postUrl, {
            method:'post',
            asynchronous:true,
            evalScripts:false,
            onComplete:function(request, json) {
            Element.hide(formId);
            Element.show('formSuccess2');
            },
            onLoading:function(request, json){
            Element.show('formLoader');
            },
            parameters: $(formId).serialize(true),
            }
            );
            }
            }

            new Event.observe(formId, 'submit', function(e){
            e.stop();
            doAjax();
            });
            //]]>
            </script>





            share|improve this answer




























              0














              Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess'); to Element.show('formSuccess2'); and added the div like this <div id="formSuccess2" style="display:none">hello</div>



              <script type="text/javascript">
              //<![CDATA[
              var formId = 'product_sendtofriend_form';
              var sendfriendForm = new VarienForm(formId, false);
              var postUrl = '<?php echo $this->getSendUrl() ?>';
              function doAjax() {
              if (sendfriendForm.validator.validate()) {
              new Ajax.Updater(
              { success:'formSuccess' }, postUrl, {
              method:'post',
              asynchronous:true,
              evalScripts:false,
              onComplete:function(request, json) {
              Element.hide(formId);
              Element.show('formSuccess2');
              },
              onLoading:function(request, json){
              Element.show('formLoader');
              },
              parameters: $(formId).serialize(true),
              }
              );
              }
              }

              new Event.observe(formId, 'submit', function(e){
              e.stop();
              doAjax();
              });
              //]]>
              </script>





              share|improve this answer


























                0












                0








                0







                Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess'); to Element.show('formSuccess2'); and added the div like this <div id="formSuccess2" style="display:none">hello</div>



                <script type="text/javascript">
                //<![CDATA[
                var formId = 'product_sendtofriend_form';
                var sendfriendForm = new VarienForm(formId, false);
                var postUrl = '<?php echo $this->getSendUrl() ?>';
                function doAjax() {
                if (sendfriendForm.validator.validate()) {
                new Ajax.Updater(
                { success:'formSuccess' }, postUrl, {
                method:'post',
                asynchronous:true,
                evalScripts:false,
                onComplete:function(request, json) {
                Element.hide(formId);
                Element.show('formSuccess2');
                },
                onLoading:function(request, json){
                Element.show('formLoader');
                },
                parameters: $(formId).serialize(true),
                }
                );
                }
                }

                new Event.observe(formId, 'submit', function(e){
                e.stop();
                doAjax();
                });
                //]]>
                </script>





                share|improve this answer













                Thanks to you pointing me in the right place to look I figured out something that worked. I changed Element.show('formSuccess'); to Element.show('formSuccess2'); and added the div like this <div id="formSuccess2" style="display:none">hello</div>



                <script type="text/javascript">
                //<![CDATA[
                var formId = 'product_sendtofriend_form';
                var sendfriendForm = new VarienForm(formId, false);
                var postUrl = '<?php echo $this->getSendUrl() ?>';
                function doAjax() {
                if (sendfriendForm.validator.validate()) {
                new Ajax.Updater(
                { success:'formSuccess' }, postUrl, {
                method:'post',
                asynchronous:true,
                evalScripts:false,
                onComplete:function(request, json) {
                Element.hide(formId);
                Element.show('formSuccess2');
                },
                onLoading:function(request, json){
                Element.show('formLoader');
                },
                parameters: $(formId).serialize(true),
                }
                );
                }
                }

                new Event.observe(formId, 'submit', function(e){
                e.stop();
                doAjax();
                });
                //]]>
                </script>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 13 '16 at 19:21









                FreejoyFreejoy

                444924




                444924

























                    0














                    Change code



                    onComplete:function(request, json) {
                    Element.hide(formId);
                    Element.show('formSuccess');
                    }


                    to:



                    onComplete:function(request, json) {                            
                    $('formSuccess').show();
                    }





                    share|improve this answer


























                    • It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

                      – Freejoy
                      Apr 13 '16 at 18:48











                    • updated answer check it

                      – Prashant Valanda
                      Apr 13 '16 at 20:07
















                    0














                    Change code



                    onComplete:function(request, json) {
                    Element.hide(formId);
                    Element.show('formSuccess');
                    }


                    to:



                    onComplete:function(request, json) {                            
                    $('formSuccess').show();
                    }





                    share|improve this answer


























                    • It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

                      – Freejoy
                      Apr 13 '16 at 18:48











                    • updated answer check it

                      – Prashant Valanda
                      Apr 13 '16 at 20:07














                    0












                    0








                    0







                    Change code



                    onComplete:function(request, json) {
                    Element.hide(formId);
                    Element.show('formSuccess');
                    }


                    to:



                    onComplete:function(request, json) {                            
                    $('formSuccess').show();
                    }





                    share|improve this answer















                    Change code



                    onComplete:function(request, json) {
                    Element.hide(formId);
                    Element.show('formSuccess');
                    }


                    to:



                    onComplete:function(request, json) {                            
                    $('formSuccess').show();
                    }






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Apr 13 '16 at 20:07

























                    answered Apr 13 '16 at 17:58









                    Prashant ValandaPrashant Valanda

                    9,55412353




                    9,55412353













                    • It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

                      – Freejoy
                      Apr 13 '16 at 18:48











                    • updated answer check it

                      – Prashant Valanda
                      Apr 13 '16 at 20:07



















                    • It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

                      – Freejoy
                      Apr 13 '16 at 18:48











                    • updated answer check it

                      – Prashant Valanda
                      Apr 13 '16 at 20:07

















                    It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

                    – Freejoy
                    Apr 13 '16 at 18:48





                    It works that way but not how it needs to work. If I put `<div id="formSuccess" style="display:none">hello</div>' it replaces the div with the whole products details page and tries to put that into the popup. I would like it to show "hello" or go get another html document. I've tried everything I can think of. Thanks

                    – Freejoy
                    Apr 13 '16 at 18:48













                    updated answer check it

                    – Prashant Valanda
                    Apr 13 '16 at 20:07





                    updated answer check it

                    – Prashant Valanda
                    Apr 13 '16 at 20:07


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Magento Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f110781%2fhow-to-display-success-message-after-ajax-form-summit%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Magento 2 controller redirect on button click in phtml file

                    Polycentropodidae