Ok I'm at my wits end and this is the last issue that needs to be resolved before we can roll out the initial version of our dedicated mobile app. I have a page in our mobile app (courses.html) that internally transitions between several jQM "pages" all the while programmatically setting lists with data. Flows like this:
courses.html
-> List of terms (#terms)
-> List of disciplines (#disciplines)
-> List of courses by discipline (#courses)
-> List of classes by course (#classes)
-> Class Info (#classinfo)
The first five jQM pages display lists. Terms displays a list that is populated by a SOAP Web Service call. The user clicks a term, the termid is stored and persisted using sessionStorage, and then the user transitions to #disciplines which is a static HTML list. The user selects a discipline, another AJAX call is made to a SOAP Web Service passing in the termid which is stored in sessionStorage along with the disciplineid which was selected from the discipline list. The user is transitioned to the #courses page and the list is updated. This goes on all the way to the end point which is class info.
I can progress all the way through the navigational flow with no problem all the while seeing appropriate data. However the problem occurs when I click the back button. As soon as I click back and then select a new option from the previous list, the list on the new page is doubled up...or more specifically the list is appended to include the old options for the previous discipline/course along with the new options (newly selected item). I've tried $('#list_coursesbycourseid').html = ''; and nothing seems to clear the list out. I suspect I'm not handling or using the correct events but I'm not entirely sure what's going on. Here's piece of code as an example. WS calls have been omitted:
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title></title>
- <link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
- <script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
- <script>
- $(document).ready(function () {
- // Load Current Terms
- getCurrentTerms();
-
- // HANDLER: Handles term click
- $('#list_terms').on('click', 'a', function () {
- // Store the selected TermID
- localStorage.termid = $(this).attr('id');
- // Change the page to show all disciplines
- $.mobile.changePage($('#disciplines'), {
- transition: "slide",
- reverse: false
- });
- });
-
- // HANDLER: Handles discipline click
- $('#list_disciplines').on('click', 'a', function () {
- // Store the selected discipline
- localStorage.disciplineid = $(this).attr('id');
- // Call the web service, passing in the selected term and selected discipline
- getCoursesByTermAndDiscipline(localStorage.termid, localStorage.disciplineid);
-
- $.mobile.changePage($('#courses'), {
- transition: "slide",
- reverse: false
- });
- });
- // HANDLER: Handles course click
- $('#list_courses').on('click', 'a', function () {
- // Store the selected discipline
- localStorage.courseid = $(this).attr('id');
- // Call the web service, passing in the selected term and selected discipline
- getCoursesByTermAndCourseId(localStorage.termid, localStorage.courseid);
- $.mobile.changePage($('#coursesbycourseid'), {
- transition: "slide",
- reverse: false
- });
- });
- });
- function getCoursesByTermAndCourseId(termid, courseid) {
- $.ajax({
- type: 'post',
- data: { "termid": termid, "courseid": courseid },
- url: '<WEB SERVICE CALL>',
- beforeSend: function () { $.mobile.loading('show') },
- timeout: 10000,
- error: function (xhr, status, error) { alert('Error: ' + xhr.status + ' - ' + error); },
- dataType: 'xml',
- success: function (response) {
- $(response).find('channel').children().each(function () {
- $.mobile.loading('hide');
- var elm = $(this);
- var courseid = elm.find('courseid').text();
- var course = elm.find('course').text();
- var classnumber = elm.find('classnumber').text();
- var campuslocation = elm.find('room').text();
- var classstartdate = elm.find('classstartdate').text();
- var classenddate = elm.find('classenddate').text();
- var instructor = elm.find('instructor').text();
- $('#list_coursesbycourseid').html = '';
- $('#list_coursesbycourseid').append('<li><a href="#" id="' + classnumber + '"><h3>' + course + '</h3><p>Class Number: ' + classnumber + '<br>Location: ' + campuslocation + '<br>Dates: ' + classstartdate + ' - ' + classenddate + '<br>Instructor: ' + instructor + '</p></a></li>');
- $('#list_coursesbycourseid').listview('refresh');
- });
- },
- failure: function (msg) { alert(msg); }
- });
- }
- function getCoursesByTermAndDiscipline(termid, disciplineid) {
- $.ajax({
- type: 'post',
- data: { "termid": termid, "disciplineid": disciplineid },
- url: '<WEB SERVICE CALL>',
- beforeSend: function () { $.mobile.loading('show') },
- timeout: 10000,
- error: function (xhr, status, error) { alert('Error: ' + xhr.status + ' - ' + error); },
- dataType: 'xml',
- success: function (response) {
- $(response).find('channel').children().each(function () {
- $.mobile.loading('hide');
- var elm = $(this);
- var courseid = elm.find('courseid').text();
- var course = elm.find('course').text();
-
- $('#list_courses').html = '';
- $('#list_courses').append('<li><a href="#" id="' + courseid + '"><h3>' + course + '</h3></a></li>');
- $('#list_courses').listview('refresh');
- });
- },
- failure: function (msg) { alert(msg); }
- });
- }
- function getCurrentTerms() {
- $.ajax({
- type: 'post',
- data: '{}',
- url: '<WEB SERVICE CALL>',
- beforeSend: function () { $.mobile.loading('show') },
- timeout: 10000,
- error: function (xhr, status, error) {alert('Error: ' + xhr.status + ' - ' + error);},
- dataType: 'xml',
- success: function (response) {
- $.mobile.loading('hide');
- $(response).find('channel').children().each(function () {
- var elm = $(this);
- var termid = elm.find('termid').text();
- var term = elm.find('term').text();
- $('#list_terms').append('<li><a href="#" id="' + termid + '"><h3>' + term + '</h3></a></li>');
- $('#list_terms').listview('refresh');
- });
- },
- failure: function (msg) {alert(msg);}
- });
- }
- </script>
- </head>
- <body>
- <div data-role="page" id="terms">
- <header>
- <a href="index.html"><img src="/mobile/images/header.png" width="310" height="85"></a>
- </header>
-
- <div data-role="header">
- <a href="index.html" data-role="button" data-mini="true" data-icon="back">Back</a>
- <h4>Select Term</h4>
- </div>
-
- <section data-role="content">
- <div class="content-primary">
- <ul data-role="listview" id="list_terms"></ul>
- </div>
- </section>
-
- <div data-role="footer"></div>
- <footer data-role="navbar">
- <ul>
- <li><a href="http://m.facebook.com/miracostacc"><img src="/images/icon_facebook.gif" width="24" height="24"></a></li>
- <li><a href="http://m.flickr.com/photos/miracosta_college/sets/"><img src="/images/icon_flickr.gif" width="24" height="24"></a></li>
- <li><a href="https://mobile.twitter.com/miracosta"><img src="/images/icon_twitter.gif" width="24" height="24"></a></li>
- <li><a href="http://m.youtube.com/user/miracostacc"><img src="/images/icon_youtube.gif" width="24" height="24"></a></li>
- <li><a href="/mobile/moreoptions.html" data-rel="dialog"><img src="images/icon_more.png" width="24" height="24"></a></li>
- </ul>
- </footer>
- </div>
- <div data-role="page" id="disciplines">
- <header>
- <a href="index.html"><img src="/mobile/images/header.png" width="310" height="85"></a>
- </header>
-
- <div data-role="header">
- <a href="#terms" data-role="button" data-mini="true" data-icon="back">Back</a>
- <h4>Disciplines</h4>
- </div>
-
- <section data-role="content">
- <div class="content-primary">
- <ul data-role="listview" id="list_disciplines" data-autodividers="true">
- <li><a href="#" id="ACCT"><h3>Accounting</h3></a></li>
- <li><a href="#" id="ADM"><h3>Administration of Justice</h3></a></li>
- <li><a href="#" id="ACE"><h3>American College English</h3></a></li>
- <li><a href="#" id="ANTH"><h3>Anthropology</h3></a></li>
- <li><a href="#" id="ARCH"><h3>Architecture</h3></a></li>
- <li><a href="#" id="ART"><h3>Art</h3></a></li>
- <li><a href="#" id="ASIA"><h3>Asian Studies</h3></a></li>
- <li><a href="#" id="ASTR"><h3>Astronomy</h3></a></li>
- <li><a href="#" id="ATHL"><h3>Athletics</h3></a></li>
- <li><a href="#" id="AUTO"><h3>Automotive Technology</h3></a></li>
- <li><a href="#" id="BIO"><h3>Biological Sciences</h3></a></li>
- <li><a href="#" id="BTEC"><h3>Biotechnology</h3></a></li>
- <li><a href="#" id="BUS"><h3>Business Administration</h3></a></li>
- <li><a href="#" id="BOT"><h3>Business Office Technology</h3></a></li>
- <li><a href="#" id="CRLP"><h3>Career and Life Planning</h3></a></li>
- <li><a href="#" id="CHEM"><h3>Chemistry</h3></a></li>
- <li><a href="#" id="CHLD"><h3>Child Development</h3></a></li>
- <li><a href="#" id="CISGT"><h3>CIS GT</h3></a></li>
- <li><a href="#" id="COMM"><h3>Communication</h3></a></li>
- <li><a href="#" id="CIS"><h3>Computer & Information Science</h3></a></li>
- <li><a href="#" id="CS"><h3>Computer Science</h3></a></li>
- <li><a href="#" id="CSIT"><h3>Computer Studies & Info Tech</h3></a></li>
- <li><a href="#" id="COUN"><h3>Counseling</h3></a></li>
- <li><a href="#" id="DNCE"><h3>Dance</h3></a></li>
- <li><a href="#" id="DESN"><h3>Design</h3></a></li>
- <li><a href="#" id="DRAF"><h3>Design Drafting Technology</h3></a></li>
- <li><a href="#" id="DRAM"><h3>Dramatic Arts</h3></a></li>
- <li><a href="#" id="EART"><h3>Earth Sciences</h3></a></li>
- <li><a href="#" id="ECON"><h3>Economics</h3></a></li>
- <li><a href="#" id="EDUC"><h3>Education</h3></a></li>
- <li><a href="#" id="ETEC"><h3>Energy Technology</h3></a></li>
- <li><a href="#" id="ENGR"><h3>Engineering</h3></a></li>
- <li><a href="#" id="ENGL"><h3>English</h3></a></li>
- <li><a href="#" id="ESL"><h3>English as a Second Language</h3></a></li>
- <li><a href="#" id="FILM"><h3>Film</h3></a></li>
- <li><a href="#" id="FREN"><h3>French</h3></a></li>
- <li><a href="#" id="GEOG"><h3>Geography</h3></a></li>
- <li><a href="#" id="GEOL"><h3>Geology</h3></a></li>
- <li><a href="#" id="GRMN"><h3>German</h3></a></li>
- <li><a href="#" id="GERO"><h3>Gerontology</h3></a></li>
- <li><a href="#" id="HEAL"><h3>Health Education</h3></a></li>
- <li><a href="#" id="HIST"><h3>History</h3></a></li>
- <li><a href="#" id="HORT"><h3>Horticulture</h3></a></li>
- <li><a href="#" id="HOSP"><h3>Hospitality</h3></a></li>
- <li><a href="#" id="HUMN"><h3>Humanities</h3></a></li>
- <li><a href="#" id="INTR"><h3>Interdisciplinary Studies</h3></a></li>
- <li><a href="#" id="ITAL"><h3>Italian</h3></a></li>
- <li><a href="#" id="JAPN"><h3>Japanese</h3></a></li>
- <li><a href="#" id="KINE"><h3>Kinesiology</h3></a></li>
- <li><a href="#" id="LRNS"><h3>Learning Skills</h3></a></li>
- <li><a href="#" id="LIBR"><h3>Library</h3></a></li>
- <li><a href="#" id="LING"><h3>Linguistics</h3></a></li>
- <li><a href="#" id="LIT"><h3>Literature</h3></a></li>
- <li><a href="#" id="MATH"><h3>Mathematics</h3></a></li>
- <li><a href="#" id="MAT"><h3>Media Arts and Technologies</h3></a></li>
- <li><a href="#" id="MAP"><h3>Medical Admin Professional</h3></a></li>
- <li><a href="#" id="MUS"><h3>Music</h3></a></li>
- <li><a href="#" id="MTEC"><h3>Music Technology</h3></a></li>
- <li><a href="#" id="NURS"><h3>Nursing</h3></a></li>
- <li><a href="#" id="NUTR"><h3>Nutrition</h3></a></li>
- <li><a href="#" id="OCEA"><h3>Oceanography</h3></a></li>
- <li><a href="#" id="PHAR"><h3>Pharmacology</h3></a></li>
- <li><a href="#" id="PHIL"><h3>Philosophy & Religious Studies</h3></a></li>
- <li><a href="#" id="PHLB"><h3>Phlebotomy</h3></a></li>
- <li><a href="#" id="PHSE"><h3>Physical Education</h3></a></li>
- <li><a href="#" id="PHSN"><h3>Physical Science</h3></a></li>
- <li><a href="#" id="PHTH"><h3>Physical Therapy</h3></a></li>
- <li><a href="#" id="PHYS"><h3>Physics</h3></a></li>
- <li><a href="#" id="PLSC"><h3>Political Science</h3></a></li>
- <li><a href="#" id="PSYC"><h3>Psychology</h3></a></li>
- <li><a href="#" id="READ"><h3>Reading</h3></a></li>
- <li><a href="#" id="REAL"><h3>Real Estate</h3></a></li>
- <li><a href="#" id="SOC"><h3>Sociology</h3></a></li>
- <li><a href="#" id="SPAN"><h3>Spanish</h3></a></li>
- <li><a href="#" id="SURG"><h3>Surgical Technology</h3></a></li>
- <li><a href="#" id="TA"><h3>Theatre Arts</h3></a></li>
- <li><a href="#" id="WKEX"><h3>Work Experience Education</h3></a></li>
- </ul>
- </div>
- </section>
-
- <div data-role="footer"></div>
- <footer data-role="navbar">
- <ul>
- <li><a href="http://m.facebook.com/miracostacc"><img src="/images/icon_facebook.gif" width="24" height="24"></a></li>
- <li><a href="http://m.flickr.com/photos/miracosta_college/sets/"><img src="/images/icon_flickr.gif" width="24" height="24"></a></li>
- <li><a href="https://mobile.twitter.com/miracosta"><img src="/images/icon_twitter.gif" width="24" height="24"></a></li>
- <li><a href="http://m.youtube.com/user/miracostacc"><img src="/images/icon_youtube.gif" width="24" height="24"></a></li>
- <li><a href="/mobile/moreoptions.html" data-rel="dialog"><img src="images/icon_more.png" width="24" height="24"></a></li>
- </ul>
- </footer>
- </div>
- <div data-role="page" id="courses">
- <header>
- <a href="index.html"><img src="/mobile/images/header.png" width="310" height="85"></a>
- </header>
-
- <div data-role="header">
- <a href="#disciplines" data-role="button" data-mini="true" data-icon="back">Back</a>
- <h4>Courses</h4>
- </div>
-
- <section data-role="content">
- <div class="content-primary">
- <ul data-role="listview" id="list_courses"></ul>
- </div>
- </section>
-
- <div data-role="footer"></div>
- <footer data-role="navbar">
- <ul>
- <li><a href="http://m.facebook.com/miracostacc"><img src="/images/icon_facebook.gif" width="24" height="24"></a></li>
- <li><a href="http://m.flickr.com/photos/miracosta_college/sets/"><img src="/images/icon_flickr.gif" width="24" height="24"></a></li>
- <li><a href="https://mobile.twitter.com/miracosta"><img src="/images/icon_twitter.gif" width="24" height="24"></a></li>
- <li><a href="http://m.youtube.com/user/miracostacc"><img src="/images/icon_youtube.gif" width="24" height="24"></a></li>
- <li><a href="/mobile/moreoptions.html" data-rel="dialog"><img src="images/icon_more.png" width="24" height="24"></a></li>
- </ul>
- </footer>
- </div>
- </body>
- </html>