if (!ajax_js) { var ajax_js = true; /* ********************* * AJAX ********************* */ // primary function to reload a container with the contents of a new url. the action is here. // RETURNS // true if HTTP request was made // false if HTTP request failed // PARAMS // id = container where data should be placed // uri = uri of data to be fetched // lid = id of status container. ajax_loader() will use this to put some message or image inside [OPTIONAL] // oid = the id of some tag we want to perform an outerHTML on in case innerHTML fails [OPTIONAL] // content = the status message we wish to load into the container with id 'lid' [OPTIONAL] function update(id,uri,lid,oid,content) { var rv = true var request, e // 200 OK // XMLHttpRequest.open( method, URL, async, userName, password ) // The "async" parameter specifies whether the request should be handled asynchronously or not – // "true" means that script processing carries on after the send() method, without waiting for a response, // and "false" means that the script waits for a response before continuing script processing. try { if (lid) { if (content) { ajax_loader(lid,'on',content) } else { ajax_loader(lid,'on') } } } catch (err) { } try { request = getXmlHttpObject() if (request == null) { return false } request.onreadystatechange = function() { try { if ( request.readyState==4 || request.readyState=="complete" ) { if (request.responseText) { e = document.getElementById(id) if (e) { e.innerHTML = request.responseText } // end element exists check if (lid) { ajax_loader(lid,'off') } // end if lid } // end if responseText } // end if readyState } // end try catch (err) { if (oid) { // innerHTML messed up. let's use outerHTML. e = document.getElementById(oid) if (e) { e.outerHTML = request.responseText } // end if e if (lid) { ajax_loader(lid,'off') } // end if lid } // end if oid } // end catch } // end function request.open("GET", uri, true) request.send('') } catch (err) { rv = false try { if (lid) { ajax_loader(lid,'off') } } catch (err) { } } return rv } function getXmlHttpObject(handler) { var objXMLHttp=null if (!window.XMLHttpRequest) { XMLHttpRequest = function() { // [Wikipedia] Here is a patch allowing direct invocation of XMLHttpRequest in browsers that don't supply one directly: try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){} try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){} try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){} try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){} throw new Error("Could not find an XMLHttpRequest alternative.") } } objXMLHttp=new XMLHttpRequest() return objXMLHttp } // ajax_loader: indicates the status of the HTTP request // PARAMS // lid = id of status container // status = on / off (on = put some content in the status container, off = make the container blank) // content = the content you want to load into the container (if left blank, default content will be used) function ajax_loader(lid,status,content) { try { var e = document.getElementById(lid) if (e) { if (status=="on") { // show the ajax loader animated gif if (content) { e.innerHTML = content } else { // default path of the animated gif to be used e.innerHTML = "" } } // end if status else { e.innerHTML = "" } // end else } // end if e } catch (err) { } } } // run once