Summary:
Assets have the wrong URL when I load them using the AJAX-based jQuery-based navigation model.
Scenario:
2 websites:
- mydomain.com β normal site (no problem here, forget about it)
- mydomain.com/mobile β mobile site
Implementation:
All mobile pages have a clean URL, e.g. mydomain.com/mobile/page i.e. mydomain.com/mobile/home , mydomain.com/mobile/aboutus , mydomain.com/mobile/contact , ...
Thus, all mobile pages have a base URL in their "main" seccion, for example
<base href="mydomain.com/mobile/" />
so that all assets work with relative (and clean) URLs.
What works:
When accessing pages using the full URL or disabling the jQuery Mobile page navigation model ( $.mobile.ajaxEnabled = false ), everything (links, assets) works like a charm.
Problem:
When I do not turn off jQuery Mobile for page navigation, the first open mobile page works fine, but after that, whenever I follow the link on the page, the new page is loaded through Ajax and injected into the DOM, but all assets / links are relative ( and clean) URLs stop working. They have the wrong URL.
Example:
When I am mydomain.com/mobile/aboutus , "aboutus" has a logo image with a relative url logo.png (absolute will be mydomain.com/mobile/logo.png ) that displays correctly. But when I am mydomain.com/mobile/home and I click on the link to mydomain.com/mobile/aboutus , the "aboutus" page is loaded, but the logo url is changed to aboutlogo.png instead of the correct logo.png
Help: http://jquerymobile.com/test/docs/pages/docs-navmodel.html
Another key component of jQuery The model of navigation on mobile pages is the basic element that is introduced into the head and changed on each page to change so that any assets (css, images, js, etc.) that the page links to will be requested from the appropriate track. In browsers that do not support dynamic updates of the base element (for example, Firefox 3.6), jQuery Mobile goes through all the link assets on the page and prefixes their href and src attributes with the base path.
Question:
ΒΏAm I doing it wrong? ΒΏThat the error or I did not understand the documentation. How can I get assets downloaded via AJAX to have the correct URL?
I want to use the navigation model for jQuery mobile pages in order to have fancy transitions in mobile browsers.
Show me the code!
mydomain.com/mobile/home code:
<!DOCTYPE html> <head> <base href="http://mydomain.com/mobile/" /> <link rel="stylesheet" href="jquery.mobile-1.0a3.min.css"> <script src="http://code.jquery.com/jquery-1.5.min.js"></script> <script src="jquery.mobile-1.0a3.min.js"></script> ... </head> <body> <div id="home" data-role="page"> <div data-role="header">Foo</div> <div data-role="content"> <a href="about">About us</a> </div> <div data-role="footer">Bar</div> </div> </body> </html>
mydomain.com/mobile/about code:
<!DOCTYPE html> <head> <base href="http://mydomain.com/mobile/" /> <link rel="stylesheet" href="jquery.mobile-1.0a3.min.css"> <script src="http://code.jquery.com/jquery-1.5.min.js"></script> <script src="jquery.mobile-1.0a3.min.js"></script> ... </head> <body> <div id="about" data-role="page"> <div data-role="header">Foo</div> <div data-role="content"> <img src="logo.png" alt=""/> <a href="home" data-role="button" data-rel="back">Back</a> </div> <div data-role="footer">Bar</div> </div> </body> </html>