本文介绍了$(window).load之后的MySQL查询以减少页面的负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在页面完全加载后,如何才能启动MySQL查询?

How I can start a MySQL query only when my page is fully loaded ?

我需要这样做是因为我的查询会影响大量数据并增加访问者页面的加载时间:/

I need that because my query impact much data and increase the time of load of the page for my visitor :/

我尝试使用此代码失败=>

I tried with this code without success =>

<script type="text/javascript">
$(window).load(function() {
<?php
include(BASE . "sql-query.php");
?>
});
</script>

推荐答案

假设存在查询的文件是sql-query.php,请使用该代码(ps:请记住包括jquery库!):

Assuming the file where there's the query is sql-query.php, use that code (ps: remember to include jquery library!):

[into <head>]
<script type="text/javascript">
$(window).load(function() {
$("#query").load("sql-query.php");
});
</script>
[into <body>]
<div id="query">Loading...</div>

这篇关于$(window).load之后的MySQL查询以减少页面的负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 19:08