2

Another issue I seem to be having is with Jquery again. I'm basically loading in content from external php pages, by using the .load function. This works fine, the only issue I have is the load just flashes in and out, so it doesn't look very good.

Is there anyway to get the loader to display for longer, or at least a min amount of time?

Here's the code I currently have:

 $('#content').load('contact.php');
        $('#test a').click(function() {
        var page = $(this).attr('href');
        $("#mydiv").html('<div class="bar"><span></span></div>');
        $('#content').load(''+ page +'.php', null, function() {
    $("#mydiv").html('');
   });
    return false;
});

Any help or guidance would be great :)

The following did not work :

<script type="text/javascript">
    $(document).ready(function() {

    setTimeout(function () { 

    $('#content').load('contact.php');


    $('#test a').click(function() {

    var page = $(this).attr('href');

        $("#mydiv").html('<div class="bar"><span></span></div>');
    $('#content').load(''+ page +'.php', null, function() {
    $("#mydiv").html('');
    });

    return false;

        }); 

    }, 2000);

});
</script>
3
  • 1
    I would recommend .ready instead of .load as there are no images in the code i m assuming. Commented Aug 24, 2012 at 20:40
  • @DhruvenkumarShah this is not the load event listener, jquery has a shorthand for loading content to a div using AJAX. Commented Aug 24, 2012 at 20:46
  • oops my bad. @sabithpocker you are right. Commented Aug 24, 2012 at 20:47

2 Answers 2

2
<script>
    setTimeout(function () { 
        //Do it here
    }, 2000);
</script>

I would not make an user wait one minute though. Modify the 2000 to whatever time you want.

Good luck.

Sign up to request clarification or add additional context in comments.

9 Comments

Thanks for the reply Hanlet, Although this seemingly didnt make a difference... Strange... It still seems to just show the loader for a second... nothing more... could it be becae im using $(document).ready() ?
Wrap the entire thing inside of the setTimeout.
If OP has #mydiv inside #content this might not work, as the call back is after inserting processed response code into #content.
This still doesnt work, when the page loads it dispaly the .load('contact.php') after 2000 doesnt work for selecting the other pages, to display the loader and then proceed with the content.
@LeeMarshall do you have #mydiv inside #content?
|
2

You can call a setTimeout to hide the loader when it has finished loading and display the content:

setTimeout(hideLoaderShowContent, 1000); // 

function hideLoaderShowContent() {
    $("#loader").hide();
    $("#content").show();
}

Edit: This is what you are needing as requested:

var $mydiv = $("#mydiv");

$mydiv.html('<div class="bar"><span></span></div>');

$('#content').load(''+ page +'.php', null, function() {
    setTimeout(function() { $mydiv.html(''); }, 1000); // Note the setTimeout here waits 1 second (1000 ms)
});  

2 Comments

Hi rcdmk, how would i implement this from my stated above code, i cant seem to work it out.
I've updated my answer, but think you have already worked it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.