-1

I have an issue, I've been searching but nothing give best answers.
My apps using jquery mobile not load any of my script in javascript except i refresh it first manually
even i try to refresh it using script, i can't
because it can't load the script.

Any suggestions?

UPDATE
I use rel="external" and it's just work great
I think I should understand more about AJAX

1 Answers1

1

How jQuery Mobile handles page changes

To understand this situation you need to understand how jQuery Mobile works. It uses ajax to load other pages.

First page is loaded normally. Its HEAD and BODY is loaded into the DOM, and they are there to await other content. When second page is loaded, only its BODY content is loaded into the DOM.

Here's an official documentation: http://jquerymobile.com/demos/1.2.0/docs/pages/page-links.html

Unfortunately you are not going to find this described in their documentation. Ether they think this is a common knowledge or they forgot to describe this like my other topics. (jQuery Mobile documentation is big but lacking many things).

Solutions:

  • In your second page, and every other page, move your SCRIPT tag into the BODY content, like this:

  • Move all of your javascript into the original first HTML. Collect everything and put it inside a single js file, into a HEAD. Initialize it after jQuery Mobile has been loaded.

  • Use rel="external" in your buttons and every elements you are using to change page. Because of it ajax is not going to be used for page loading and your jQuery Mobile app will behave like a normal web application.

More informations

More information with working examples can be found in my blog ARTICLE or even HERE.

Community
  • 1
  • 1
Gajotres
  • 57,309
  • 16
  • 102
  • 130