Strange behaviour back button and $.mobile.changePage
We are quite new with JQuery mobile and managed to do multiple pages in single HTML working well.
In our browse.html page we have pages for
- practice-list-page
- practiceitem-list-page
- practiceitem-detail-page
The page flow between one page is working well. But then after few back and forth between pages (either through back button or click on listview then redirect $.mobile.changePage, page flow has a strange behaviour ie. practiceitem-detail-page page twice. It seem like remembering the history of previous click/tap.
Even we've tried on mobileinit as follow:
$.mobile.hashListeningEnabled = false;
//$.mobile.pushStateEnabled = false;
$.mobile.changePage.defaults.changeHash = false;
Didn't help either. We tested with both Chrome and IE and it's the same behaviour.
We are using:
I'm appreciated your feedback.
Thanks
- <!DOCTYPE html>
- <html>
- <head>
- <title>Test Home</title>
- <meta name="viewport" />
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.css" />
- <style>
- .ui-li-desc {
- white-space:normal;
- }
-
- </style>
- <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
- <script type="text/javascript">
- // This mobileinit method needs to be put before JQueryM
-
- $(document).on( "mobileinit", function() {
- $.mobile.hashListeningEnabled = false;
- //$.mobile.linkBindingEnabled = false;
- $.mobile.pushStateEnabled = true;
- $.mobile.changePage.defaults.changeHash = false;
-
- console.log('pass');
- var storedsitepreference = localStorage.getItem('account-login');
- var IS_JSON = true;
- try
- {
- var accountloginjson = $.parseJSON(storedsitepreference);
- ls_userid = accountloginjson.userid;
- ls_username = accountloginjson.username;
- }
- catch(err)
- {
- IS_JSON = false;
- console.log('error');
- }
-
-
- });
- </script>
- <script src="http://code.jquery.com/mobile/1.4.3/jquery.mobile-1.4.3.min.js"></script>
-
- <script type="text/javascript">
-
- $(document).on('pagebeforeshow', '#practice-list-page', function()
- {
- var page = pageObject.page;
- var reclimit = pageObject.reclimit;
-
- userid = ls_userid;
- username = ls_username;
-
- var url = 'http://practice.dewagear.com/webservices/',
- mode = 'server.php?',
- queryName = '&query=GetPractices',
- parameters = 'userid=' + userid + '&page=' + page + '&reclimit=' + reclimit ,
- key = 'api_key=470fd2ec8853e25d2f8d86f685d2270e';
- $.ajax({
- type: 'GET',
- url: url + mode + parameters + queryName,
- dataType: "jsonp",
- jsonpCallback: "GetPractices",
- contentType: 'application/json; charset=utf-8',
- success: function (result)
- {
- $('#practice-list-listview').empty();
- $.each(result, function(i, row) {
- $('#practice-list-listview').append('<li data-datecreated="' + row.datecreated + '" id="prd_' + row.practiceid + '"><a href="#"><h3>' + row.name + '</h3><p>' + row.practicetypecategoryname + ', ' + row.noofreps + ' reps</p></a></li>');
- });
- $('#practice-list-listview').listview({
- autodividers:true,
- autodividersSelector: function (li) {
- var d = new Date(li.data("datecreated"));
-
- console.log(d);
-
- var curdate = d.getDate();
- var curmonth = d.getMonth();
- curmonth++;
- var curyear = d.getFullYear();
-
- var dateSubmit = curdate + '/' + curmonth + '/' + curyear;
-
- return dateSubmit;
- }
- }).listview('refresh');
-
-
- },
- error: function (jqXHR, textStatus, errorThrown) {
- console.log(url + mode + parameters + queryName),
- console.log(errorThrown);
- console.log(textStatus);
-
- }
- });
-
- $(document).on('click', '#practice-list-listview li',function (event) {
- pageObject.practiceid = $(this).attr("id").substr(4);
- $.mobile.changePage("#practiceitem-list-page", { transition: "fade" });
- });
-
- });
-
- $(document).on('pagebeforeshow', '#practiceitem-list-page', function()
- {
- console.log("#practiceitem-list-page - pass - start");
- var practiceid = pageObject.practiceid;
-
- var url = 'http://practice.dewagear.com/webservices/',
- mode = 'server.php?',
- queryName = 'query=GetPracticeItems',
- parameter = '&practiceid=' + practiceid,
- key = 'api_key=470fd2ec8853e25d2f8d86f685d2270e';
-
- console.log(url + mode + queryName + parameter);
-
- $.ajax({
- type: 'GET',
- url: url + mode + queryName + parameter,
- beforeSend : function() {$.mobile.loading('show')},
- complete : function() {$.mobile.loading('hide')},
- dataType: "jsonp",
- jsonpCallback: "GetPracticeItems",
- contentType: 'application/json; charset=utf-8',
- success: function (result)
- {
- $('#practiceitem-list-listview').empty();
- $.each(result, function(i, row) {
- //console.log(JSON.stringify(row));
- $('#practiceitem-list-listview').append('<li id="pid_' + row.practiceitemid + '"><a href="#"><h3>' + row.name + ' (' + row.sequenceno + ')</h3><p>Measurements: ' + row.measurename1 + ' / ' + row.measurename2 + ' / ' + row.measurename3 + '</p></a></li>');
- });
- $('#practiceitem-list-listview').listview('refresh');
-
-
- },
- error: function (jqXHR, textStatus, errorThrown) {
- console.log(errorThrown);
- console.log(textStatus);
-
- }
- });
-
- $(document).on('click', '#practiceitem-list-listview li',function (event) {
-
- console.log('pass - #practiceitem-list-page - tap - start');
-
- pageObject.practiceitemid = $(this).attr("id").substr(4);
-
- $.mobile.changePage("#practiceitem-detail-page", { transition: "slide" });
-
- console.log('pass - #practiceitem-list-page - tap - end');
- });
-
- console.log('pass - #practiceitem-list-page - end');
- });
-
- $(document).on('pagebeforeshow', '#practiceitem-detail-page', function()
- {
- console.log('pass - #practiceitem-detail-page - start');
-
- $(document).on('click', '#save_button', function (event) {
- console.log('pass - #practiceitem-detail-page - save_button - start');
-
- practiceitemid = pageObject.practiceitemid;
-
- var measureoptionid1 = $('#measureoptionid1').val();
- var measureoptionid2 = $('#measureoptionid2').val();
- var measureoptionid3 = $('#measureoptionid3').val();
-
- var url = 'http://practice.dewagear.com/webservices/',
- mode = 'server.php?',
- queryName = 'query=UpdatePracticeItem',
- parameter = '&practiceitemid=' + practiceitemid + '&measureoptionid1=' + measureoptionid1 + '&measureoptionid2=' + measureoptionid2 + '&measureoptionid3=' + measureoptionid3,
- key = 'api_key=470fd2ec8853e25d2f8d86f685d2270e';
-
- console.log(url + mode + queryName + parameter);
-
- $.ajax({
- type: 'GET',
- url: url + mode + queryName + parameter,
- beforeSend : function() {$.mobile.loading('show')},
- complete : function() {$.mobile.loading('hide')},
- dataType: "jsonp",
- jsonpCallback: "UpdatePracticeItem",
- contentType: 'application/json; charset=utf-8',
- success: function (result)
- {
- $.mobile.changePage("#practiceitem-list-page", { transition: "slide" });
- },
- error: function (jqXHR, textStatus, errorThrown) {
- console.log(errorThrown);
- console.log(textStatus);
-
- }
- });
-
- console.log('pass - #practiceitem-detail-page - save_button - end');
-
-
- });
-
- console.log('pass - #practiceitem-detail-page - end');
-
-
- });
-
- // Store object
- var pageObject = {
- userid : '',
- username : '',
- practiceid : '',
- practiceitemid : '',
- page : '',
- reclimit : ''
- }
-
- </script>
-
- </head>
- <body>
- <div data-role="page" id="practice-list-page">
- <div data-theme="a" data-role="header" data-position="fixed" >
- <h3 id="SiteTitle">Browse</h3>
- <div data-role="navbar">
- <ul>
- <li><a href="browse.html" data-ajax="false" data-icon="home" data-iconpos="notext" data-role="button">Home</a></li>
- <li><a href="post.html" data-ajax="false" data-icon="plus">Post Practice</a></li>
- <li><a href="post.html" data-ajax="false" data-icon="plus">Analysis</a></li>
- </ul>
- </div>
- </div>
- <div data-role="content" data-theme="a" data-fullscreen="true">
- <div class="example-wrapper" data-iscroll>
- <ul data-role="listview" id="practice-list-listview" data-theme="a" data-inset="true"></ul>
- </div>
- </div>
- <div data-theme="a" data-role="footer" data-position="fixed" >
- <div data-role="navbar" >
- <ul>
- <li><a href="preference.html" data-ajax="false" data-icon="location" data-iconpos="notext" data-role="button">Change Network</a></li>
- <li><a href="#" data-icon="user" data-iconpos="notext" data-role="button">Contact Us</a></li>
- <li><a href="content.html" data-ajax="false" data-icon="star" data-iconpos="notext" data-role="button">About</a></li>
- </ul>
- </div>
- </div>
- </div>
- <div data-role="page" id="practiceitem-list-page">
- <div data-theme="a" data-role="header" data-position="fixed" >
- <a href="#practice-list-page" class="ui-btn-left" data-rel="back" data-transition="slide" id="back-to-ads">Back</a>
- <h3 id="SiteTitle">Browse</h3>
- <div data-role="navbar">
- <ul>
- <li><a href="browse.html" data-ajax="false" data-icon="home" data-iconpos="notext" data-role="button">Home</a></li>
- <li><a href="post.html" data-ajax="false" data-icon="plus">Post Practice</a></li>
- <li><a href="post.html" data-ajax="false" data-icon="plus">Analysis</a></li>
- </ul>
- </div>
- </div>
- <div data-role="content" data-theme="a" data-fullscreen="true">
- <div class="example-wrapper" data-iscroll>
- <ul data-role="listview" id="practiceitem-list-listview" data-theme="a" data-inset="true">
- <li data-role="list-divider" data-theme="a">Select a practice item</li>
- </ul>
-
- </div>
- </div>
- <div data-theme="a" data-role="footer" data-position="fixed" >
- <div data-role="navbar" >
- <ul>
- <li><a href="preference.html" data-ajax="false" data-icon="location" data-iconpos="notext" data-role="button">Change Network</a></li>
- <li><a href="#" data-icon="user" data-iconpos="notext" data-role="button">Contact Us</a></li>
- <li><a href="content.html" data-ajax="false" data-icon="star" data-iconpos="notext" data-role="button">About</a></li>
- </ul>
- </div>
- </div>
- </div>
- <div data-role="page" id="practiceitem-detail-page">
- <div data-theme="a" data-role="header" data-position="fixed">
- <a href="#practiceitem-list-page" class="ui-btn-left" data-rel="back" data-transition="slide" id="back-to-ads">Back</a>
- <h3 id="SiteTitle">Home</h3>
- <div data-role="navbar">
- <ul>
- <li><a href="browse.html" data-ajax="false" data-icon="home" data-iconpos="notext" data-role="button">Home</a></li>
- <li><a href="post.html" data-ajax="false" data-icon="plus">Post Ad</a></li>
- <li><a href="#" data-icon="navigation" data-iconpos="notext" data-role="button">Change City</a></li>
- </ul>
- </div>
- </div>
- <div data-role="content" data-theme="a" data-fullscreen="true">
- <fieldset data-role="controlgroup" data-type="horizontal" class="custom-fieldset">
- <legend>Measurements:</legend>
- <select name="measureoptionid1" id="measureoptionid1" data-icon="false">
- <option value="1" selected>Good </option>
- <option value="2">Not Bad </option>
- <option value="3">Bad </option>
- </select>
- <select name="measureoptionid2" id="measureoptionid2" data-icon="false">
- <option value="8" selected>Straight</option>
- <option value="4">Left</option>
- <option value="5">Right</option>
- <option value="6">Short</option>
- <option value="7">Long</option>
- <option value="11">Not Applicable</option>
- </select>
- <select name="measureoptionid3" id="measureoptionid3" data-icon="false">
- <option value="9" selected>Perfect</option>
- <option value="10">Not Perfect (X)</option>
- <option value="12">Not Applicable</option>
- </select>
- </fieldset>
- <button class="" id="save_button">Save</button>
- </div>
- <div data-theme="a" data-role="footer" data-position="fixed" >
- <div data-role="navbar" >
- <ul>
- <li><a href="preference.html" data-ajax="false" data-icon="location" data-iconpos="notext" data-role="button">Change Network</a></li>
- <li><a href="#" data-icon="user" data-iconpos="notext" data-role="button">Contact Us</a></li>
- <li><a href="content.html" data-ajax="false" data-icon="star" data-iconpos="notext" data-role="button">About</a></li>
- </ul>
- </div>
- </div>
- </div>
- </body>
- </html>