2013-05-01 56 views
0

我有两个包含PHP代码的jQueryMobile页面。在页面A上,我有一个显示MySQL数据库内容的SELECT。页面B提供了将数据添加到数据库的可能性。现在,当从页面A导航到页面B(通过changePage)并返回到页面A并带有“返回”按钮时,SELECT的内容(当然)不会刷新。导航后用php内容刷新jQueryMobile页面

什么是在jQueryMobile中做到这一点的正确方法?这里最重要的是页面的PHP部分需要被执行,并且SELECT需要被更新。

非常感谢!

回答

0

你拥有的PHP运行第一页就需要

$(document).on("pagebeforeshow", "#yourpageid", function() { 

)};

这只会在你的php select是通过jquery调用创建时才起作用。在我的情况下,我发现创建jQuery元素与PHP结果是从长远来看更容易。

在我的情况我有这个。

<div data-role="fieldcontain"> 
         <script type="text/javascript"> 
          $(document).on("pagebeforeshow", "#index4", function() { 
           $(function(){ 
            var items=""; 
            $.getJSON("ajaxResponder.php?method=getContacts",function(data){ 
            $.each(data,function(index,item) 
            { 
            items+="<option value='"+item.email+"'>"+item.username+"</option>"; 
            }); 
            $("#contacts").html(items); 
            $("#contacts").trigger("change"); 
            }); 
           }); 
          }); 
         </script> 
         <select name="contacts[]" id="contacts" multiple="multiple" data-native-menu="false"> 
         </select> 
        </div> 

没有任何代码示例以及如何编写代码,这是我的最佳答案。

相关问题