jQuery Mobile的loadPage不工作工作、jQuery、Mobile、loadPage

2023-09-10 19:56:17 作者:小熊陪你看月亮

唉,我这样做question前补天,但不知道如果我是清楚的。

well, i did this question fill days ago, but dont know if i was clear.

所以,我做了一些现在使用的另一种功能更简单 $。mobile.loadPage

so, i made something more simple now using another function $.mobile.loadPage

我想要做的仅仅是从另一个文件装载一个内容,一个div,就像 $。使用正常的jQuery AJAX

what i'm trying to do is just load a content from another file to a div, just like $.ajax using normal jquery.

在我的主页:

<div data-role="page">
    <button id="load" style="border: solid blue;">Click here to load</button>
    <div data-role="content" id="target">
    <!-- ajax load here -->
    </div>
</div>

这是从另一个文件的HTML:

<div id="secondPage" style="border:solid red;">
   <p>test</p>
</div>

最后,在JS:

 $("body").on("click", "#load", function () {
    $.mobile.loadPage("mobile/favorites", {
        pageContainer: $('#target'),
        type: 'post',
        reloadPage: true
    });
});

没有误差修改,在我看来,该URL加载内容,我检查了镀铬调试。

no erros appears to me, the url load the content as i checked in the chrome debug.

所以,我错过了什么?

推荐答案

您code试图在另一个页面加载一个页面。第二页( ID =secondPage),缺少的只是数据角色=页面属性。

Your code is attempting to load one page within another page. The second page (id="secondPage") is missing is data-role="page" attribute.

我从来没有试图完成你正试图在这里的话,但它还是很迷惑的基础上的文档。

I have never tried to accomplish what you are attempting here but it seems confusing based on the docs.

的方法加载的网页时,将它插入在DOM一个容器(未另一页)的内部。该 reloadPage 参数强制加载的页面刷新,如果它已经存在于DOM(有previously被加载)。不是你想要做什么。

The method loads a page, inserts it in the DOM inside of a container (not another page). The reloadPage parameter forces the loaded page to refresh if it is already in the DOM (having previously been loaded). Not what you want to do.

您将通过jQuery更好的运气加载内容,插入到DOM $(#myDiv)的负载(AJAX / test.html的); 和再刷新当前页面 $(#我的空间)页(消灭)页(); 请注意,这最后一点可能并不需要,如果你是只需插入HTML不是由jQuery Mobile的提高。

You will have better luck loading content via jQuery, inserting into the DOM $("#myDiv").load("ajax/test.html"); and then refreshing the current page with $("#myPage").page("destroy").page(); Note that this last bit may not be needed if you are simply inserting html that is not enhanced by jQuery Mobile.

 
精彩推荐
图片推荐