getting data from MySQL on jquerymobile only when I refresh the page

扶醉桌前 提交于 2019-12-02 09:50:18

Basically when jQuery mobile loads first or index page it load whole head section (Javascript, CSS etc) and body section. but When the user clicks a link in a jQuery Mobile-driven site, the default behavior of the navigation system is to use that link's href to formulate an Ajax request (instead of allowing the browser's default link behavior of requesting that href with full page load).When that Ajax request goes out, the framework will receive its entire text content, but it will only inject the contents of the response's body element.

There can be multiple solutions to this problem e.g.

  • The simplest approach when building a jQuery Mobile site is to reference the same set of stylesheets and scripts in the head of every page.

  • Linking without Ajax by using an attribute data-ajax="false" in your link this attribute will load the next page without ajax and animation so both head and body section would load.

  • If you need to load in specific scripts or styles for a particular page, It is recommended binding logic to the pageInit e.g. "#aboutPage" is id="aboutPage" attribute .

     $( document ).delegate("#aboutPage", "pageinit", function() {
       //you can place your getJson script here. that will execute when page loads 
       alert('A page with an ID of "aboutPage" was just created by jQuery Mobile!');
     });
    

So in your case better solution is to bind your ajax call or other particuler script with pageinit event.

You can get help from these pages of jQuery Mobile documentation.

http://jquerymobile.com/demos/1.1.0/docs/pages/page-links.html

http://jquerymobile.com/demos/1.1.0/docs/pages/page-scripting.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!