Skip to content

Commit cf4ab9b

Browse files
committed
Merge pull request #36 from amplitude/ie10_xdomain_request
pass response code in xdr callback
2 parents a4e8a65 + 831c3ea commit cf4ab9b

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Unreleased
22

3+
* Fix bug where response code is not passed to XDomainRequest callback (affects IE versions 10 and lower).
4+
35
## 2.6.1 (November 6, 2015)
46

57
* Localstorage is not persisted across subdomains, reverting cookie data migration and adding a reverse migration path for users already on 2.6.0.

amplitude.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2261,8 +2261,18 @@ Request.prototype.send = function(callback) {
22612261
var xdr = new window.XDomainRequest();
22622262
xdr.open('POST', this.url, true);
22632263
xdr.onload = function() {
2264-
callback(xdr.responseText);
2264+
callback(200, xdr.responseText);
22652265
};
2266+
xdr.onerror = function () {
2267+
// status code not available from xdr, try string matching on responseText
2268+
if (xdr.responseText === 'Request Entity Too Large') {
2269+
callback(413, xdr.responseText);
2270+
} else {
2271+
callback(500, xdr.responseText);
2272+
}
2273+
};
2274+
xdr.ontimeout = function () {};
2275+
xdr.onprogress = function() {};
22662276
xdr.send(querystring.stringify(this.data));
22672277
} else {
22682278
var xhr = new XMLHttpRequest();

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/xhr.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,18 @@ Request.prototype.send = function(callback) {
1414
var xdr = new window.XDomainRequest();
1515
xdr.open('POST', this.url, true);
1616
xdr.onload = function() {
17-
callback(xdr.responseText);
17+
callback(200, xdr.responseText);
1818
};
19+
xdr.onerror = function () {
20+
// status code not available from xdr, try string matching on responseText
21+
if (xdr.responseText === 'Request Entity Too Large') {
22+
callback(413, xdr.responseText);
23+
} else {
24+
callback(500, xdr.responseText);
25+
}
26+
};
27+
xdr.ontimeout = function () {};
28+
xdr.onprogress = function() {};
1929
xdr.send(querystring.stringify(this.data));
2030
} else {
2131
var xhr = new XMLHttpRequest();

0 commit comments

Comments
 (0)