Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made vjs.get work with xDomain in IE < 10 #1095

Closed
29 changes: 22 additions & 7 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ vjs.createTimeRange = function(start, end){
vjs.get = function(url, onSuccess, onError){
var local, request;

onError = onError || function(){};
if (typeof XMLHttpRequest === 'undefined') {
window.XMLHttpRequest = function () {
try { return new window.ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch (e) {}
Expand All @@ -584,8 +585,26 @@ vjs.get = function(url, onSuccess, onError){
}

request = new XMLHttpRequest();
if(!('withCredentials' in request) && window.XDomainRequest) {
request = new window.XDomainRequest();
request.onload = function() {
onSuccess(request.responseText);
};
request.onprogress = function() {};
request.onerror = onError;
request.ontimeout = onError;
try {
request.open('GET', url);
request.send();
} catch (e) {
onError(e);
}
return;
}

try {
request.open('GET', url);
request.withCredentials = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this always be set?

request.open('GET', url, true);
} catch(e) {
onError(e);
}
Expand All @@ -597,19 +616,15 @@ vjs.get = function(url, onSuccess, onError){
if (request.status === 200 || local && request.status === 0) {
onSuccess(request.responseText);
} else {
if (onError) {
onError();
}
onError();
}
}
};

try {
request.send();
} catch(e) {
if (onError) {
onError(e);
}
onError(e);
}
};

Expand Down