سؤال

I'm working on a project where I'm using jQuery Mobile, HTML5 and PhoneGap Build to create a cross platform app. The platforms we are targeting include Symbian^3.

I need to be able to keep track of some session data such as the user's ID and whether they're logged in. Symbian is a pain when it comes to this as none of the solutions I've tried seem to work.

I've tried:

  • HTML5 sessionStorage and localStorage. Both of these cause the app on Symbian to freeze as soon as they are called.
  • Cookies. These always return Undefined, even if you access them right after setting them.
  • Global variables. I've created a .js with some var's defined for use across the app. This script is included in the head of each HTML file where it may be needed. Unfortunately this doesn't work since the variables are redefined when you switch between pages, losing the session data.

I've reached the limit of what I can accomplish through Web searches and experimentation, so I'm asking my first ever question on here. I'd be happy to upload some code samples though there really isn't much to show.

As for the actual question: How can I create a session context in a jQuery Mobile app on Symbian such that it persists across page transitions?

هل كانت مفيدة؟

المحلول

You need to understand how JQM is working. When you start on page A and go to page B, you are not really leaving page A. Instead JQM AJAX-requests page B, strips everything outside <div data-role="page"></div> and appends this to the DOM.

This means your DOM will always stay "alive", no matter where in your application you go (unless you set data-ajax="false" on links).

Because of this, your option 3 - global variables - should work, since the a.js file will only be loaded on page A (and stripped out on page B, C, D...). If variables are overwritten, it will be because you are probably overwriting them - you'd need to show what's inside a.js.

Another option would be to attach the information that should persist to the DOM directly, either using data()(api) like:

 $('html').data("foo": bar)

or if it's not that much info, just use a data-attribute

 $('html').jqmData("some","thing");
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top