加载页面时加载,而不是点击等等(ajax,php)

时间:2022-11-28 21:00:30
$(function(){  
    $('p.load_it a').click(function(){  
        $('#demo_content').load('http://d.com/myphp.php?  nice=1149632');  
        return false;  
    });  
});  
Click me to load some HTML with AJAX.

    <div id='demo_content'> 

    </div> 

I wanted to know if anyone can give me advice as to how I can load this kind of Effect not by a click, but by an animated "loading" effect.

我想知道是否有人可以给我建议如何加载这种效果不是通过点击,而是通过动画“加载”效果。

Let me know if anyone has any suggestions.

如果有人有任何建议,请告诉我。

3 个解决方案

#1


2  

This will execute your load() call when the DOM on the page is ready.

这将在页面上的DOM准备好时执行load()调用。

$(document).ready(function() {
    $('#demo_content').load('http://example.com/myphp.php? nice=1149632');
    return false;
});

As for your 'loading' request, I suggest you take a look at this * question. Nevermind, I just saw you already had something in mind.

至于你的“加载”请求,我建议你看看这个*问题。没关系,我刚看到你已经有了想法。

#2


2  

$(document).ready(function() {
    $.ajax({
      url: 'http://example.com/myphp.php?nice=1149632',
      success: function(data) {
        $('#demo_content').html(data);
      }
    beforeSend: function(){
        //show loading here
        $('#demo_content').html("Loading...");
    }
    });
});

#3


1  

If you want the javascript code to be executed when the page has been loaded, you can also add the script at the bottom of the page, like this:

如果您希望在加载页面时执行javascript代码,您还可以在页面底部添加脚本,如下所示:

<script>
$('#demo_content').load('http://example.com/myphp.php? nice=1149632');
</script>

#1


2  

This will execute your load() call when the DOM on the page is ready.

这将在页面上的DOM准备好时执行load()调用。

$(document).ready(function() {
    $('#demo_content').load('http://example.com/myphp.php? nice=1149632');
    return false;
});

As for your 'loading' request, I suggest you take a look at this * question. Nevermind, I just saw you already had something in mind.

至于你的“加载”请求,我建议你看看这个*问题。没关系,我刚看到你已经有了想法。

#2


2  

$(document).ready(function() {
    $.ajax({
      url: 'http://example.com/myphp.php?nice=1149632',
      success: function(data) {
        $('#demo_content').html(data);
      }
    beforeSend: function(){
        //show loading here
        $('#demo_content').html("Loading...");
    }
    });
});

#3


1  

If you want the javascript code to be executed when the page has been loaded, you can also add the script at the bottom of the page, like this:

如果您希望在加载页面时执行javascript代码,您还可以在页面底部添加脚本,如下所示:

<script>
$('#demo_content').load('http://example.com/myphp.php? nice=1149632');
</script>