, :
$(".tweets").html('Retrieving...');
:
<div id="ajax_tweets" class="tweets">
<div id="ajax_message"></div>
</div>
... , :
$(document).ready(function() {
window.setInterval(ajax_test, 10000);
counter = 0;
var $message = $("#ajax_message");
function ajax_test() {
$message.html('Retrieving...');
$.ajax({
type: "POST",
url: "assets/ajax/get_latest_tweets.php",
data: "tid=" + id,
timeout: 20000,
success: function(msg) {
$message.html('');
if (msg != "") {
add_to_tweet_feed( msg );
id++;
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$message.html('Timeout contacting server..');
}
});
}
function add_to_tweet_feed ( msg ) {
$(msg).insertBefore($message);
}
});
: ( insertBefore()). , , :
$(document).ready(function() {
window.setInterval(ajax_test, 10000);
counter = 0;
var $message = $("#ajax_message");
function ajax_test() {
$message.html('Retrieving...');
var $placeholder = $('<div></div>').insertBefore($message).hide();
$.ajax({
type: "POST",
url: "assets/ajax/get_latest_tweets.php",
data: "tid=" + id,
timeout: 20000,
success: function(msg) {
$message.html('');
if (msg != "") {
add_to_tweet_feed(msg, $placeholder);
id++;
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$placeholder.remove();
$message.html('Timeout contacting server..');
}
});
}
function add_to_tweet_feed (msg, $placeholder) {
$placeholder.show().replaceWith(msg);
}
});