AJAX

Note for me. AJAX Code.

 var http;

 function keepSessionOpen(){
    window.setTimeout('keepSessionOpen()', 1200000); // 1 200 000 = every 20 minutes
    var myurl = "#{statusBean.link}/page/status.xhtml";
    http = http.open("POST", myurl, true);
    http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    http.setRequestHeader("Connection", "Keep-Alive");
    http.onreadystatechange = useHttpResponse;
    http.send(null);
 }

 function getHTTPObject() {
    if (typeof XMLHttpRequest != 'undefined') {
        return new XMLHttpRequest();
    }
    try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            return new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e) {
            alert(e);
        }
    }
    return false;
 }

function useHttpResponse() {
    if (http.readyState == 4 && this.status != 200) {
        alert(this.status);
    }
}

Published by Robert Reiz

CEO @ VersionEye. Passionated software developer since 1998.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: