I was going through the chrome debugger and I noticed the following odd item. At some point in the following code:
Tools.LoadFile = function (url, onSuccess, onProgress, offlineProvider, useArrayBuffer, onError) {
url = Tools.CleanUrl(url);
url = Tools.PreprocessUrl(url);
// If file and file input are set
if (url.indexOf("file:") !== -1) {
var fileName = decodeURIComponent(url.substring(5).toLowerCase());
if (BABYLON.FilesInput.FilesToLoad[fileName]) {
return Tools.ReadFile(BABYLON.FilesInput.FilesToLoad[fileName], onSuccess, onProgress, useArrayBuffer);
}
}
var loadUrl = Tools.BaseUrl + url;
var aborted = false;
var fileRequest = {
onCompleteObservable: new BABYLON.Observable(),
abort: function () { return aborted = true; },
};
var requestFile = function () {
var request = new XMLHttpRequest();
var retryHandle = null;
fileRequest.abort = function () {
aborted = true;
if (request.readyState !== (XMLHttpRequest.DONE || 4)) {
request.abort();
}
if (retryHandle !== null) {
clearTimeout(retryHandle);
retryHandle = null;
}
};
var retryLoop = function (retryIndex) {
request.open('GET', loadUrl, true);
if (useArrayBuffer) {
request.responseType = "arraybuffer";
}
if (onProgress) {
request.addEventListener("progress", onProgress);
}
var onLoadEnd = function () {
request.removeEventListener("loadend", onLoadEnd);
fileRequest.onCompleteObservable.notifyObservers(fileRequest);
fileRequest.onCompleteObservable.clear();
};
request.addEventListener("loadend", onLoadEnd);
var onReadyStateChange = function () {
if (aborted) {
return;
}
// In case of undefined state in some browsers.
if (request.readyState === (XMLHttpRequest.DONE || 4)) {
// Some browsers have issues where onreadystatechange can be called multiple times with the same value.
request.removeEventListener("readystatechange", onReadyStateChange);
if ((request.status >= 200 && request.status < 300) || (request.status === 0 && (!Tools.IsWindowObjectExist() || Tools.IsFileURL()))) {
onSuccess(!useArrayBuffer ? request.responseText : request.response, request.responseURL);
return;
}
var retryStrategy = Tools.DefaultRetryStrategy;
if (retryStrategy) {
var waitTime = retryStrategy(loadUrl, request, retryIndex);
if (waitTime !== -1) {
// Prevent the request from completing for retry.
request.removeEventListener("loadend", onLoadEnd);
request = new XMLHttpRequest();
retryHandle = setTimeout(function () { return retryLoop(retryIndex + 1); }, waitTime);
return;
}
}
var e = new LoadFileError("Error status: " + request.status + " " + request.statusText + " - Unable to load " + loadUrl, request);
if (onError) {
onError(request, e);
}
else {
throw e;
}
}
};
request.addEventListener("readystatechange", onReadyStateChange);
if (Tools.UseCustomRequestHeaders) {
Tools.InjectCustomRequestHeaders(request);
}
request.send();
I noticed that at the start it contains the proper loadUrl.
request.open('GET', loadUrl, true);
In the debugger it shows that it has the correct link to the file which in my case is:
“digitalrealitiesplatform.azurewebsites.net/Models/Aviation/Airplane/shark.glb”
but at some point in this section it changes:
if (request.readyState === (XMLHttpRequest.DONE || 4)) {
// Some browsers have issues where onreadystatechange can be called multiple times with the same value.
request.removeEventListener("readystatechange", onReadyStateChange);
if ((request.status >= 200 && request.status < 300) || (request.status === 0 && (!Tools.IsWindowObjectExist() || Tools.IsFileURL()))) {
onSuccess(!useArrayBuffer ? request.responseText : request.response, request.responseURL);
return;
}
the response URL changes to:
responseURL: "http://digitalrealitiesplatform.azurewebsites.net/index.php/product/aviation-model/digitalrealitiesplatform.azurewebsites.net/Models/Aviation/Airplane/shark.glb"
Somewhere the string is changed and I guess tries to approach this new location but I can’t seem to figure out when the change occurs.