1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| window.addEventListener("DOMContentLoaded", init, false);
var coca = {};
coca.tweet = {};
coca.tweet.data = {};
var xhr = null;
var test;
function init(){
register_tweet();
show_tweet();
update_tweet();
coca.tweet.getXMLHttpRequest();
coca.timer = setInterval(function(){coca.tweet.get_tweet()}, 1500);
}
coca.tweet.getXMLHttpRequest = function(){
if (window.XMLHttpRequest || window.ActiveXObject) {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
} else {
xhr = new XMLHttpRequest();
}
} else {
alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
return null;
}
return xhr;
}
coca.tweet.get_tweet = function(callback){
xhr = coca.tweet.getXMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
coca.tweet.callback_get_tweet(xhr.responseText);
}
};
xhr.open("GET", "./count_length.php", true);
xhr.send(null);
}
coca.tweet.callback_get_tweet = function(sData){
coca.tweet.data = eval('(' + sData + ')');
console.log(coca.tweet.data);
coca.tweet.display_tweet();
}
coca.tweet.display_tweet = function(){
// alert(coca.tweet.data);
if(coca.tweet.data >100){
// register_tweet();
// show_tweet();
// update_tweet();
}
else{
}
}
//Function qui charge toute les 15 secondes pour insérer les nouveaux tweets
function register_tweet()
{
$.ajax({
url: 'register_tweet.php',
});
setTimeout('register_tweet()',2000);
}
//Function qui charge toute les 15 secondes pour récupérer les tweets
function show_tweet()
{
$.ajax({
url: 'show_tweet.php',
success: function(data)
{
if(data!=0)
{
$('#nombre').show();
$('#nombre').html(data);
}
}
});
setTimeout('show_tweet()',2000);
}
function update_tweet(){
$.ajax({
url: 'update_tweet.php',
success: function(data)
{
}
})
setTimeout('update_tweet()',4800);
} |
Partager