Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lastMessageID = 0;
- function getXHR() {
- var xhr = null;
- 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();
- }
- }
- return xhr;
- }
- function ajax_req_and_callback(page, callback) {
- var xhr = getXHR();
- xhr.open("GET", page);
- xhr.send(null);
- xhr.onreadystatechange = function() {
- if(xhr.readyState == 4)
- callback(xhr.responseText);
- }
- }
- function MaJSiNouveauxMessages() {
- ajax_req_and_callback("messages.php?count", function(r) {
- if(r > lastMessageID) {
- ajax_req_and_callback("messages.php?depuis="+lastMessageID, function(a) {
- document.getElementById("messages").innerHTML += a;
- });
- lastMessageID = r;
- }
- });
- }
- var updateMsgTimer = window.setInterval(MaJSiNouveauxMessages, 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement