在加载移动应用程序页面时调用Javascript函数

call a Javascript function when a mobile app page loads

本文关键字:调用 Javascript 函数 加载 移动 应用程序      更新时间:2023-09-26

我有一个移动应用程序,它有多个页面。在其中一个页面上,我有一些javascript,它向php页面发送请求以获取一些数据。

现在,数据被完美地返回,但是一旦主索引页加载并立即显示数据,它就会加载。我想做的是只在主index.html页面中的特定页面打开时显示信息。

下面是直接加载数据的代码。

  $(document).ready(function(){
  $.ajax({    //create an ajax request to load_page.php
    type: "GET",
    url: "http://domain/group_list.php",             
    dataType: "html",   //expect html to be returned                
    success: function(response){                    
        $("#responsecontainer").html(response); 
        //alert(response);
    }
 });
 });

我试着把它改成这个,但当我这样做的时候,信息根本没有显示。

     $(document).on('pageinit', '#three', function(){
  $.ajax({    //create an ajax request to load_page.php
    type: "GET",
    url: "http://domain/group_list.php",             
    dataType: "html",   //expect html to be returned                
    success: function(response){                    
        $("#responsecontainer").html(response); 
        //alert(response);
    }
   });
 });

所以我添加的代码已经过时了,应该是下面显示的代码,一旦我进行了这些更改,它就可以完美地工作了。

  $(document).on("pagecreate","#three",function(event){
         $.ajax({    //create an ajax request to load_page.php
type: "GET",
url: "http://domain/group_list.php",             
dataType: "html",   //expect html to be returned                
success: function(response){                    
    $("#responsecontainer").html(response); 
    //alert(response);
}
  });
 });