As far as I know of course it will have that delay. Suppose your page containing <div id="feedback">[…]</div>
is loaded at 0th second now:
$(document).ready(function() {
$.ajax({
url: 'do.php',
success: function(data){
$('#feedback').html(data);
});
});
Is called as apparently it’s visible when document loads. So suppose its called at 3rd second when the document is ready—you can refer to this page for details—now you will be seeing that feedback
div blank for 3 seconds.
I can suggest 2 things:
You can place a loader image by default inside the div so your code will change to
<div id="feedback"><img src='loader.gif'></div>
(Assume you have theloader.gif
in the same directory of the page). By doing this you will make the user visually understand that some processing is going on and will load data.Instead if you can place
file_get_contents()
orinclude()
so it will look something like this<div id="feedback"><?php file_get_contents('do.php');?></div>
or<div id="feedback"><?php include('do.php');?></div>
As far as I knowfile_get_contents
will execute the page and then load while include will load and then execute hence in include() you have the variables in the page available whereas infile_get_contents
are not available but CSS would work in both cases.