X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=js%2Fpz2.js;h=b4de590eec4361985502c1ab116dab791fa4d948;hb=91cbaff33f868dd36f1bce0f8a4411a374cd34ca;hp=9eaae43331fcf925bededb1ddc12bb1671e5b869;hpb=fca562549bc185f9bbde0a2bb7219a5083803a46;p=pazpar2-moved-to-github.git diff --git a/js/pz2.js b/js/pz2.js index 9eaae43..b4de590 100644 --- a/js/pz2.js +++ b/js/pz2.js @@ -1,5 +1,5 @@ /* -** $Id: pz2.js,v 1.28 2007-06-01 09:19:58 jakub Exp $ +** $Id: pz2.js,v 1.34 2007-06-13 16:07:43 jakub Exp $ ** pz2.js - pazpar2's javascript client library. */ @@ -314,7 +314,9 @@ pz2.prototype = { } else { var nodeName = hits[i].childNodes[j].nodeName; - var nodeText = hits[i].childNodes[j].firstChild.nodeValue; + var nodeText = 'ERROR' + if ( hits[i].childNodes[j].firstChild ) + nodeText = hits[i].childNodes[j].firstChild.nodeValue; show.hits[i][nodeName] = nodeText; } } @@ -352,6 +354,7 @@ pz2.prototype = { if ( recordNode = data.getElementsByTagName("record")[0] ) { // if stylesheet was fetched do not parse the response if ( __myself.xslDoc ) { + record['recid'] = recordNode.getElementsByTagName("recid")[0].firstChild.nodeValue; record['xmlDoc'] = data; record['xslDoc'] = __myself.xslDoc; } else { @@ -416,8 +419,10 @@ pz2.prototype = { //for each term in the list for (j = 0; j < terms.length; j++) { var term = { - "name": terms[j].getElementsByTagName("name")[0].childNodes[0].nodeValue, - "freq": terms[j].getElementsByTagName("frequency")[0].childNodes[0].nodeValue + "name": (terms[j].getElementsByTagName("name")[0].childNodes.length + ? terms[j].getElementsByTagName("name")[0].childNodes[0].nodeValue + : 'ERROR'), + "freq": terms[j].getElementsByTagName("frequency")[0].childNodes[0].nodeValue || 'ERROR' }; var termIdNode = terms[j].getElementsByTagName("id"); @@ -511,6 +516,7 @@ var pzHttpRequest = function ( url, errorHandler ) { this.request = null; this.url = url; this.errorHandler = errorHandler || null; + this.async = true; if ( window.XMLHttpRequest ) { this.request = new XMLHttpRequest(); @@ -527,8 +533,28 @@ pzHttpRequest.prototype = { get: function ( params, callback ) { + this._send( 'GET', params, null, callback ); + }, + + post: function ( params, data, callback ) + { + this._send( 'POST', params, data, callback ); + }, + + _send: function ( type, params, data, callback ) + { this.callback = callback; - + var context = this; + this.request.open( type, this._urlAppendParams(params), this.async ); + //this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + this.request.onreadystatechange = function () { + context._handleResponse(); + } + this.request.send(data); + }, + + _urlAppendParams: function (params) + { var getUrl = this.url; var paramArr = new Array(); @@ -539,14 +565,7 @@ pzHttpRequest.prototype = if ( paramArr.length ) getUrl += '?' + paramArr.join('&'); - var context = this; - this.request.open( 'GET', getUrl, true ); - this.request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); - //this.request.setRequestHeader('Accept-Charset', 'UTF-8'); - this.request.onreadystatechange = function () { - context._handleResponse(); - } - this.request.send(null); + return getUrl; }, _handleResponse: function ()