} else if (this.useSessions) {
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
{ "command": "init" },
function(data) {
if ( data.getElementsByTagName("status")[0]
);
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
{ "command": "ping", "session": this.sessionID },
function(data) {
if ( data.getElementsByTagName("status")[0]
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
searchParams,
function(data) {
if ( data.getElementsByTagName("status")[0]
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
{ "command": "stat", "session": this.sessionID },
function(data) {
if ( data.getElementsByTagName("stat") ) {
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
{
"command": "show",
"session": this.sessionID,
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
recordParams,
function(data) {
var recordNode;
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
{
"command": "termlist",
"session": this.sessionID,
var context = this;
var request = new pzHttpRequest(this.pz2String, this.errorHandler);
- request.get(
+ request.postParams(
{ "command": "bytarget", "session": this.sessionID },
function(data) {
if ( data.getElementsByTagName("status")[0]
this.url = url;
this.errorHandler = errorHandler || null;
this.async = true;
+ this.requestHeaders = {};
if ( window.XMLHttpRequest ) {
this.request = new XMLHttpRequest();
pzHttpRequest.prototype =
{
+ postParams: function ( params, callback )
+ {
+ this.requestHeaders["Content-Type"]="application/x-www-form-urlencoded";
+ this._send('POST', {}, this.encodeParams(params), callback);
+ },
+
get: function ( params, callback )
{
this._send( 'GET', params, '', callback );
return this.request.responseXML;
},
+ encodeParams: function (params)
+ {
+ var sep = "";
+ var encoded = "";
+ for (var key in params) {
+ if (params[key] != null) {
+ encoded += sep + key + '=' + encodeURIComponent(params[key]);
+ sep = '&';
+ }
+ }
+ return encoded;
+ },
+
_send: function ( type, params, data, callback )
{
this.callback = callback;
var context = this;
this.async = true;
this.request.open( type, this._urlAppendParams(params), this.async );
+ for (var key in this.requestHeaders)
+ this.request.setRequestHeader(key, this.requestHeaders[key]);
this.request.onreadystatechange = function () {
context._handleResponse();
}
_urlAppendParams: function (params)
{
- var getUrl = this.url;
-
- var sep = '?';
- var el = params;
- for (var key in el) {
- if (el[key] != null) {
- getUrl += sep + key + '=' + encodeURIComponent(el[key]);
- sep = '&';
- }
- }
- return getUrl;
+ var encodedParams = this.encodeParams(params);
+ if (encodedParams)
+ return this.url + "?" + encodedParams;
+ else
+ return this.url;
},
_handleResponse: function ()