ons-back-button with refresh = true does not work


  • Onsen UI

    @mmike Check this example in Safari and see if it works. That’s a simple init event. Perhaps you are not adding the listeners soon enough in your app? Not sure. For example, event listeners should not be added inside ons.ready because that delays it.



  • Here is the code. It works perfectly fine in chrome/firefox not in safari.

      <ons-page id="rPage">
      <div class="left"><ons-back-button>Search</ons-back-button></div>
      <div id="allResults" style="text-align: left; margin-left:10px; margin-top: 30px;"></div>
      <script>
        document.addEventListener('init', function(event) {
         var page = event.target;
         if (page.matches('#rPage')) {
          console.log("hello");
          $.ajax({url : "/api/get_results?src=1",
          type: "POST",
          data: "str1=N&str2=1",
          success: function(data, textStatus, jqXHR) {
                     $("#allResults").html(data);
                   },
          error: function(jqXHR, textStatus, errorThrown) {
                   ons.notification.alert({message: "Error ...",title: ""});
                 }
          });
         }
        });
      </script>
      </ons-page>


  •     });

  • Onsen UI

    @mmike Move that script to <head>...</head> and try again :+1: (or include it with <script src="..."></script>



  • Fran,

    That will not work for me because Ajax data: str1 and str2 are dynamically derived from previous page.

    The above code is generated from php. str1 and str2 parameters are available in php. If I move it to index.html, those str1 and str2 are not available.

    Any thoughts?

    Can ons-page have <head></head??

    I appreciate your help.


  • Onsen UI

    @mmike Not, it cannot have a head element. The important thing here is to register the listener before the actual event is fired. Safari might be running your code later than the other browsers so the init event has already been fired by the time the code is executed (so the listener is added too late). We don’t recommend using <script> tags inside <ons-page> to add event listeners precisely because of this unpredictable behavior of some browsers. Can’t you pass your variables in pushPage(..., { data: { /* custom data */ } }) to that page?



  • Ok Fran. How do I read the data in pushPage()?

    Thanks



  • That worked, Fran!

    Thanks!



  • Hi Fran,

    Now that I send the data in options.data in pushPage when I popPage() , this options.data is not available.

    Sorry for asking too many questions.

    Thanks for your help!



  • Never mind…


Log in to reply