2015-09-12 62 views
0

这是我使用从一个php文件加载网页的初始数据与砌体布局AJAX

$.ajax({ 
     type: "post", 
     url: "content.php", 
     data: somevariable, 
     dataType: "text",     
     success: function(response) { 
     $(this).parent().find(".loadingdataimage").hide(); 
     $content.html(response); 
     }.bind(this) 
    }); 

现在得到的数据我怎样才能使这个代码从页的初始数据的AJAX content.php文件每当页面加载

+1

我不知道我理解的问题,正确的,但我会假设你只是想调用这段代码中的“文件准备”处理程序。 – Octopoid

+0

是当页面加载,以便我可以从数据库使用ajax调用 –

+0

从数据库中获取数据将帮助,如果我直接使用文档准备? @octopoid –

回答

1

@Octopoid是正确的解决方案,下面教你如何使用jQuery做一个例子:

$.ready(function() { 
    $.ajax({ 
    type: "post", 
    url: "content.php", 
    data: somevariable, 
    dataType: "text",     
    success: function(response) { 
     $(this).parent().find(".loadingdataimage").hide(); 
     $content.html(response); 
    }.bind(this) 
    }); 
}); 

如果你想逻辑分离成一个功能,你可以再打电话,你可以做到这样的:

var refresh = function() { 
    $.ajax({ 
    type: "post", 
    url: "content.php", 
    data: somevariable, 
    dataType: "text",     
    success: function(response) { 
     $(this).parent().find(".loadingdataimage").hide(); 
     $content.html(response); 
    }.bind(this) 
    }); 
} 
$.ready(refresh);