Cảm ơn bạn rất nhiều vì wrapper của bạn. Với sự giúp đỡ của bạn, tôi đã có thể tạo ra một máy dò xmlrequest cho IE và FF và phần còn lại.
Tôi đã thêm một phiên bản (kết hợp từ một ví dụ khác) mà làm việc cho FF, IE và phần còn lại của băng đảng,
if(window.XMLHttpRequest)
{
var XMLHttpRequest = window.XMLHttpRequest;
// mystery: for some reason, doing "var oldSend = XMLHttpRequest.prototype.send;" and
// calling it at the end of "newSend" doesn't work...
var startTracing = function() {
XMLHttpRequest.prototype.uniqueID = function() {
// each XMLHttpRequest gets assigned a unique ID and memorizes it
// in the "uniqueIDMemo" property
if (!this.uniqueIDMemo) {
this.uniqueIDMemo = Math.floor(Math.random() * 1000);
}
return this.uniqueIDMemo;
}
// backup original "open" function reference
XMLHttpRequest.prototype.oldOpen = XMLHttpRequest.prototype.open;
var newOpen = function(method, url, async, user, password) {
console.log("[" + this.uniqueID() + "] intercepted open (" +
method + " , " +
url + " , " +
async + " , " +
user + " , " +
password + ")");
this.oldOpen(method, url, async, user, password);
}
XMLHttpRequest.prototype.open = newOpen;
// backup original "send" function reference
XMLHttpRequest.prototype.oldSend = XMLHttpRequest.prototype.send;
var newSend = function(a) {
console.log("[" + this.uniqueID() + "] intercepted send (" + a + ")");
var xhr = this;
var onload = function() {
console.log("[" + xhr.uniqueID() + "] intercepted load: " +
xhr.status +
" " + xhr.responseText);
};
var onerror = function() {
console.log("[" + xhr.uniqueID() + "] intercepted error: " +
xhr.status);
};
xhr.addEventListener("load", onload, false);
xhr.addEventListener("error", onerror, false);
this.oldSend(a);
}
XMLHttpRequest.prototype.send = newSend;
}
startTracing();
}
else if (window.ActiveXObject) {
var ActualActiveXObject = ActiveXObject;
var ActiveXObject = function(progid) {
var ax = new ActualActiveXObject(progid);
if (progid.toLowerCase() == "msxml2.xmlhttp") {
var o = {
_ax: ax,
_status: "fake",
responseText: "",
responseXml: null,
readyState: 0,
status: 0,
statusText: 0,
onReadyStateChange: null
};
o._onReadyStateChange = function() {
var self = o;
return function() {
self.readyState = self._ax.readyState;
if (self.readyState == 4) {
self.responseText = self._ax.responseText;
self.responseXml = self._ax.responseXml;
self.status = self._ax.status;
self.statusText = self._ax.statusText;
}
if (self.onReadyStateChange) self.onReadyStateChange();
}
}();
o.open = function(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword) {
console.log("intercepted open (" +
bstrMethod + " , " +
bstrUrl + " , " +
varAsync + " , " +
bstrUser + " , " +
bstrPassword + ")");
varAsync = (varAsync !== false);
this._ax.onReadyStateChange = this._onReadyStateChange
return this._ax.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword);
};
o.send = function(varBody) {
return this._ax.send(varBody);
};
}
else
var o = ax;
return o;
}
}
Tôi không nghĩ rằng điều này sẽ càng tốt. Có nguồn cho Tconnetor không? Bạn có thể phân phối lại các tệp nhị phân cho khách hàng và/hoặc phân phối các tệp nhị phân của riêng bạn nếu bạn không sở hữu nó không? – AnthonyWJones
Tôi không có nguồn, nhưng tôi có một giấy phép cho phép tôi phân phối lại nó một cách tự do. Dù bằng cách nào, tại sao tất cả các vấn đề này nếu tôi thực hiện một đối tượng javascript proxy để gọi proxy đến đối tượng activeX? – mkoryak
@mkoryak: Tôi đã xóa/cập nhật mã trong câu trả lời của mình và tôi đã tạo câu trả lời liên kết trong câu hỏi khác của bạn. – Tomalak