From 52ead6bc0391e0c85cdba31e83cd38e661a514c6 Mon Sep 17 00:00:00 2001 From: Thomas BrĂ¼derli Date: Tue, 28 Aug 2007 20:46:27 +0000 Subject: Better separation (if/else) of XMLHTTP usage --- itjs/loader.js | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'itjs') diff --git a/itjs/loader.js b/itjs/loader.js index 324661a..0208d5a 100644 --- a/itjs/loader.js +++ b/itjs/loader.js @@ -65,42 +65,44 @@ load: function(baseurl, pos, num, query_volatile, retry) if (num > 0) { + this.loader = null; + if (retry) baseurl += "&retry=" + retry; - try + // use XMLHTTP request if available + if (baseurl.indexOf('http://') < 0 || baseurl.indexOf(window.location.hostname) > 0) { - if (!(baseurl.indexOf('http://') == 0 && baseurl.indexOf(window.location.hostname) < 0)) + try + { this.loader = new XMLHttpRequest(); - } - catch (e) - { - var classnames = [ 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ]; - - for (var i in classnames) + } + catch (e) { - try + var classnames = [ 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP' ]; + + for (var i in classnames) { - this.loader = new ActiveXObject(classnames[i]); - break; + try + { + this.loader = new ActiveXObject(classnames[i]); + break; + } + catch (e) { } } - catch (e) {} } - } - try - { - this.loader.open(this.method, baseurl + "&pos=" + pos + "&num=" + num + (query_volatile ? query_volatile : "")); - var me = this; - this.loader.onreadystatechange = function() { me.readyStateChanged(); } - var workingxmlhttp = this.loader.onreadystatechange; + try + { + this.loader.open(this.method, baseurl + "&pos=" + pos + "&num=" + num + (query_volatile ? query_volatile : "")); + var me = this; + this.loader.onreadystatechange = function() { me.readyStateChanged(); } + var workingxmlhttp = this.loader.onreadystatechange; - if (!workingxmlhttp) /* Old Konqueror */ - this.loader = null; - } - catch (e) - { - this.loader = null; + if (!workingxmlhttp) /* Old Konqueror */ + this.loader = null; + } + catch (e) { } } if (this.loader) @@ -115,6 +117,7 @@ load: function(baseurl, pos, num, query_volatile, retry) else { var req_url = baseurl + "&pos=" + pos + "&num=" + num + (query_volatile ? query_volatile : "") + (this.post_data ? '&' + this.post_data : "") + "&itjs_call=it_loader.__inst" + this.instance + ".dataReady&itjs_callid=" + ++this.callid; + if (window.opera && !window.XMLHttpRequest) // Opera 7 only works with iframes { this.scrpt = document.createElement("iframe"); -- cgit v1.2.3