2010-09-17 05:24:35 +08:00
|
|
|
Ajax.Request.prototype.response = function(responseOptions) {
|
|
|
|
this.transport.readyState = 4;
|
|
|
|
if (typeof(responseOptions) == "string") {
|
|
|
|
responseOptions = {responseText: responseOptions};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.transport.responseHeaders = responseOptions.responseHeaders ||
|
|
|
|
{"Content-type": responseOptions.contentType || Ajax.Response.defaultContentType};
|
|
|
|
this.transport.status = typeof(responseOptions.status) == "undefined" ? 200 : responseOptions.status;
|
|
|
|
this.transport.responseText = responseOptions.responseText;
|
|
|
|
this.transport.onreadystatechange();
|
|
|
|
};
|
|
|
|
|
|
|
|
Ajax.Response.defaultContentType = "application/json";
|
|
|
|
Ajax.Request.prototype.oldRequest = Ajax.Request.prototype.request;
|
|
|
|
|
|
|
|
Ajax.Request.prototype.request = function(url) {
|
|
|
|
this.oldRequest(url);
|
|
|
|
ajaxRequests.push(this);
|
|
|
|
};
|
|
|
|
|
|
|
|
Ajax.RealRequest = Class.create(Ajax.Request, {
|
|
|
|
request: function(url) {
|
|
|
|
this.transport = Try.these(
|
|
|
|
function() {
|
|
|
|
return new XMLHttpRequest()
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
return new ActiveXObject('Msxml2.XMLHTTP')
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
return new ActiveXObject('Microsoft.XMLHTTP')
|
|
|
|
}
|
|
|
|
) || false;
|
|
|
|
this.oldRequest(url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-09-17 05:49:46 +08:00
|
|
|
// generic
|
|
|
|
|
2010-09-17 05:24:35 +08:00
|
|
|
var ajaxRequests = [];
|
|
|
|
|
2010-09-17 05:49:46 +08:00
|
|
|
function FakeAjaxTransport() {
|
|
|
|
this.overrideMimeType = false;
|
|
|
|
this.readyState = 0;
|
|
|
|
this.setRequestHeader = jasmine.createSpy("setRequestHeader");
|
|
|
|
this.open = jasmine.createSpy("open");
|
|
|
|
this.send = jasmine.createSpy("send");
|
|
|
|
this.abort = jasmine.createSpy("abort");
|
|
|
|
|
|
|
|
this.getResponseHeader = function(name) {
|
2010-09-17 05:24:35 +08:00
|
|
|
return this.responseHeaders[name];
|
2010-09-17 05:49:46 +08:00
|
|
|
};
|
|
|
|
}
|
2010-09-17 05:24:35 +08:00
|
|
|
|
|
|
|
function mostRecentAjaxRequest() {
|
|
|
|
if (ajaxRequests.length > 0) {
|
|
|
|
return ajaxRequests[ajaxRequests.length - 1];
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function clearAjaxRequests() {
|
|
|
|
ajaxRequests = [];
|
|
|
|
}
|