Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
BojanJurca authored Dec 22, 2023
1 parent d011bc2 commit 894651b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions moreExamples/CrossOrigin_firstServer.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,27 @@
var httpClient = function () {
this.request = function (url, method, callback) {
var httpRequest = new XMLHttpRequest ();
var httpRequestTimeout;
var httpRequestTimeout = null;

httpRequest.onreadystatechange = function () {
// console.log (httpRequest.readyState);
if (httpRequest.readyState == 1) { // 1 = OPENED, start timing
httpRequestTimeout = setTimeout (function () { alert ('Server did not reply (in time).'); }, 3000);
clearTimeout (httpRequestTimeout);
httpRequestTimeout = setTimeout (function () {
alert ('Server did not reply (in time).');
// errorMessage ('Server did not reply (in time).');
}, 5000);
}
if (httpRequest.readyState == 4) { // 4 = DONE, call callback function with responseText
clearTimeout (httpRequestTimeout);
// console.log (httpRequest.responseText);
if (httpRequest.status == 200) callback (httpRequest.responseText); // 200 = OK
else alert ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText); // some other reply status, like 404, 503, ...
switch (httpRequest.status) {
case 200: callback (httpRequest.responseText); // 200 = OK
break;
case 0: break;
default: alert ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText); // some other reply status, like 404, 503, ...
// errorMessage ('Server reported error ' + httpRequest.status + ' ' + httpRequest.responseText);
break;
}
}
}
httpRequest.open (method, url, true);
Expand Down

0 comments on commit 894651b

Please sign in to comment.