Changeset 551 in tmcsimulator for trunk/webapps/common/js/fileutils.js
- Timestamp:
- 12/26/2019 03:14:52 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/webapps/common/js/fileutils.js (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/webapps/common/js/fileutils.js
r442 r551 1 // Load the dynamic json file for highways, etc. 2 // Ref: https://codepen.io/KryptoniteDove/post/load-json-file-locally-using-pure-javascript 3 function loadJSON(inFile, callback) 1 // Load the dynamic json file for highways, etc. 2 // Ref: https://codepen.io/KryptoniteDove/post/load-json-file-locally-using-pure-javascript 3 function loadJSON(inFile, callback) 4 { 5 var xobj = new XMLHttpRequest(); 6 // Assume XML unless filename ends with .json 7 if (inFile.endsWith(".json")) 4 8 { 5 var xobj = new XMLHttpRequest(); 6 // Assume XML unless filename ends with .json 7 if (inFile.endsWith(".json")) 9 xobj.overrideMimeType("application/json"); 10 } 11 if (inFile.endsWith(".csv")) 12 { 13 xobj.overrideMimeType("text/csv"); 14 } 15 xobj.open('GET', inFile, true); 16 xobj.onreadystatechange = function() 17 { 18 if (xobj.readyState == 4 && xobj.status == "200") 8 19 { 9 xobj.overrideMimeType("application/json");20 callback(xobj.responseText); 10 21 } 11 if (inFile.endsWith(".csv")) 12 { 13 xobj.overrideMimeType("text/csv"); 14 } 15 xobj.open('GET', inFile, true); 16 xobj.onreadystatechange = function() 17 { 18 if (xobj.readyState == 4 && xobj.status == "200") 19 { 20 callback(xobj.responseText); 21 } 22 }; 23 // We want ajax to ignore any cached responses 24 xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT') 25 xobj.send(null); 22 }; 23 // We want ajax to ignore any cached responses 24 xobj.setRequestHeader('If-Modified-Since', 'Sat, 01 Jan 2000 01:01:01 GMT') 25 xobj.send(null); 26 } 27 28 /* Retrieve URL parameters passed to a web page 29 @return a dictionary of key/value pairs 30 */ 31 function getQueryParms() 32 { 33 var items = {}; 34 var query = window.location.search.substring(1); 35 var parms = query.split("&"); 36 // Examine each parameter 37 for (var i = 0, max = parms.length; i < max; i++) 38 { 39 // check for trailing & with no param 40 if (parms[i] === "") 41 continue; // skip it 42 43 var param = parms[i].split("="); 44 // If it's valid add it to dictionary 45 items[decodeURIComponent(param[0])] = decodeURIComponent(param[1] || ""); 26 46 } 27 47 return items 48 }
Note: See TracChangeset
for help on using the changeset viewer.
