| OLD | NEW |
| 1 // This goes before everything else to keep console message line number invarian
t. | 1 // This goes before everything else to keep console message line number invarian
t. |
| 2 var lastXHRIndex = 0; | 2 var lastXHRIndex = 0; |
| 3 function xhrLoadedCallback() | 3 function xhrLoadedCallback() |
| 4 { | 4 { |
| 5 // We need to make sure the console message text is unique so that we don't
end up with repeat count update only. | 5 // We need to make sure the console message text is unique so that we don't
end up with repeat count update only. |
| 6 console.log("XHR loaded: " + (++lastXHRIndex)); | 6 console.log("XHR loaded: " + (++lastXHRIndex)); |
| 7 } | 7 } |
| 8 | 8 |
| 9 var initialize_NetworkTest = function() { | 9 var initialize_NetworkTest = function() { |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 function makeSimpleXHRWithPayload(method, url, async, payload, callback) | 98 function makeSimpleXHRWithPayload(method, url, async, payload, callback) |
| 99 { | 99 { |
| 100 makeXHR(method, url, async, undefined, undefined, [], false, payload, callba
ck) | 100 makeXHR(method, url, async, undefined, undefined, [], false, payload, callba
ck) |
| 101 } | 101 } |
| 102 | 102 |
| 103 function makeXHR(method, url, async, user, password, headers, withCredentials, p
ayload, type, callback) | 103 function makeXHR(method, url, async, user, password, headers, withCredentials, p
ayload, type, callback) |
| 104 { | 104 { |
| 105 var xhr = new XMLHttpRequest(); | 105 var xhr = new XMLHttpRequest(); |
| 106 xhr.responseType = type; | 106 if (type == undefined) |
| 107 xhr.responseType = ""; |
| 108 else |
| 109 xhr.responseType = type; |
| 107 xhr.onreadystatechange = function() | 110 xhr.onreadystatechange = function() |
| 108 { | 111 { |
| 109 if (xhr.readyState === XMLHttpRequest.DONE) { | 112 if (xhr.readyState === XMLHttpRequest.DONE) { |
| 110 if (typeof(callback) === "function") | 113 if (typeof(callback) === "function") |
| 111 callback(); | 114 callback(); |
| 112 } | 115 } |
| 113 } | 116 } |
| 114 xhr.open(method, url, async, user, password); | 117 xhr.open(method, url, async, user, password); |
| 115 xhr.withCredentials = withCredentials; | 118 xhr.withCredentials = withCredentials; |
| 116 for (var i = 0; i < headers.length; ++i) | 119 for (var i = 0; i < headers.length; ++i) |
| 117 xhr.setRequestHeader(headers[i][0], headers[i][1]); | 120 xhr.setRequestHeader(headers[i][0], headers[i][1]); |
| 118 xhr.send(payload); | 121 xhr.send(payload); |
| 119 } | 122 } |
| 120 | 123 |
| 121 function makeXHRForJSONArguments(jsonArgs) | 124 function makeXHRForJSONArguments(jsonArgs) |
| 122 { | 125 { |
| 123 var args = JSON.parse(jsonArgs); | 126 var args = JSON.parse(jsonArgs); |
| 124 makeXHR(args.method, args.url, args.async, args.user, args.password, args.he
aders || [], args.withCredentials, args.payload, args.type, xhrLoadedCallback); | 127 makeXHR(args.method, args.url, args.async, args.user, args.password, args.he
aders || [], args.withCredentials, args.payload, args.type, xhrLoadedCallback); |
| 125 } | 128 } |
| OLD | NEW |