X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=js%2Fpz2.js;h=8ae13790f77e414a38e31016eac75941648622af;hb=73d850607f4b24e591405c59b2accd475d73c054;hp=becef3391e4158a938108b849555f67410155a89;hpb=c24c7254b8a48abef8df4e195405f5e58b8aaf43;p=pazpar2-moved-to-github.git diff --git a/js/pz2.js b/js/pz2.js index becef33..8ae1379 100644 --- a/js/pz2.js +++ b/js/pz2.js @@ -768,23 +768,26 @@ pz2.prototype = ** AJAX HELPER CLASS *********************************************************** ******************************************************************************** */ -var pzHttpRequest = function ( url, errorHandler ) { +var pzHttpRequest = function (url, errorHandler, cookieDomain) { this.maxUrlLength = 2048; this.request = null; this.url = url; this.errorHandler = errorHandler || null; this.async = true; this.requestHeaders = {}; - this.isXDomain = false; + this.isXDR = false; this.domainRegex = /https?:\/\/([^:/]+).*/; + this.cookieDomain = cookieDomain || null; var xhr = new XMLHttpRequest(); + var domain = this._getDomainFromUrl(url); if ("withCredentials" in xhr) { // XHR for Chrome/Firefox/Opera/Safari. - } else if (typeof XDomainRequest != "undefined") { - // XDomainRequest for IE. + } else if (domain && this._isCrossDomain(domain) && + typeof XDomainRequest != "undefined") { + // use XDR (IE7/8) when no other way xhr = new XDomainRequest(); - this.isXDomain = true; + this.isXDR = true; } else { // CORS not supported. } @@ -843,6 +846,7 @@ pzHttpRequest.prototype = _getDomainFromUrl: function (url) { + if (this.cookieDomain) return this.cookieDomain; //explicit cookie domain var m = this.domainRegex.exec(url); return (m && m.length > 1) ? m[1] : null; }, @@ -854,6 +858,7 @@ pzHttpRequest.prototype = _isCrossDomain: function (domain) { + if (this.cookieDomain) return true; //assume xdomain is cookie domain set return !this._strEndsWith(domain, document.domain); }, @@ -911,12 +916,12 @@ pzHttpRequest.prototype = } } this.request.open( type, url, this.async ); - if (!this.isXDomain) { + if (!this.isXDR) { //setting headers is only allowed with XHR for (var key in this.requestHeaders) this.request.setRequestHeader(key, this.requestHeaders[key]); } - if (this.isXDomain) { + if (this.isXDR) { this.request.onload = function () { //fake XHR props context.request.status = 200; @@ -953,7 +958,7 @@ pzHttpRequest.prototype = // pick up appplication errors first var errNode = null; // xdomainreq does not have responseXML - if (this.isXDomain) { + if (this.isXDR) { if (this.request.contentType.match(/\/xml/)){ var dom = new ActiveXObject('Microsoft.XMLDOM'); dom.async = false;