source: tmcsimulator/trunk/webapps/common/js/fileutils.js @ 557

Revision 557, 1.4 KB checked in by jdalbey, 6 years ago (diff)

Add crewcontact file to callout layer. Implements #231

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