AjxPost.js
Summary
No overview generated for 'AjxPost.js'
Class Summary
|
AjxPost |
This singleton class makes an HTTP POST to the server and receives the response, passing returned data
to a callback. |
AjxPostRequest |
|
function AjxPost(iframeId) {
this._callback = null;
this._iframeId = iframeId;
}
AjxPost._reqIds = 0;
AjxPost._outStandingRequests = new Object();
AjxPost.SC_CONTINUE = 100;
AjxPost.SC_OK = 200;
AjxPost.SC_ACCEPTED = 202;
AjxPost.SC_BAD_REQUEST = 400;
AjxPost.SC_UNAUTHORIZED = 401;
AjxPost.SC_REQUEST_TIMEOUT = 408;
AjxPost.SC_CONFLICT = 409;
AjxPost.SC_REQUEST_ENTITY_TOO_LARGE = 413;
AjxPost.SC_INTERNAL_SERVER_ERROR = 500;
AjxPost.SC_BAD_GATEWAY = 502;
AjxPost.SC_SERVICE_UNAVAILABLE = 503;
AjxPost.prototype.execute =
function(callback, form, optionalTimeout) {
form.target = this._iframeId;
this._callback = callback;
var req = new AjxPostRequest(form);
var failureAction = new AjxTimedAction(this, this._onFailure, [req.id]);
var timeout = optionalTimeout? optionalTimeout: 5000;
AjxPost._outStandingRequests[req.id] = req;
req.send(failureAction, timeout);
};
AjxPost.prototype._onFailure =
function (reqId){
var req = AjxPost._outStandingRequests[reqId];
req.cancel();
delete AjxPost._outStandingRequests[reqId];
if (this._callback) {
this._callback.run([404]);
this._callback = null;
}
};
AjxPost.prototype.loaded =
function(status, reqId, id) {
var req = AjxPost._outStandingRequests[reqId];
if (req && !req.hasBeenCancelled()) {
req.cancelTimeout();
}
delete AjxPost._outStandingRequests[reqId];
if (this._callback) {
this._callback.run(status, id);
this._callback = null;
}
};
function AjxPostRequest (form) {
this.id = AjxPost._reqIds++;
this._cancelled = false;
this._form = form;
var inp = form.elements.namedItem("requestId");
if (!inp) {
inp = form.ownerDocument.createElement('input');
inp.type = "hidden";
inp.name = "requestId";
}
inp.value = this.id;
form.appendChild(inp);
};
AjxPostRequest.prototype.send =
function(failureAction, timeout) {
this._form.submit();
};
AjxPostRequest.prototype.hasBeenCancelled =
function() {
return this._cancelled;
};
AjxPostRequest.prototype.cancelTimeout =
function() {
AjxTimedAction.cancelAction(this._timeoutId);
};
AjxPostRequest.prototype.cancel =
function() {
this._cancelled = true;
};
Documentation generated by
JSDoc on Thu Apr 27 13:58:40 2006