Javascript gotTempleJSON - jcobban/Genealogy GitHub Wiki
function gotTempleJSON(response)
The function gotTempleJSON
handles the Javascript Object Notation (JSON) response from invocation of the script /Family/getTempleJSON.php
to a search of the database for matching instances of class Temple
requested by function templeChanged
. The parameter response
is a Javascript object. The function modifies the input field or displays a dialog based upon the response.
The response from the server is a JSON document such as:
{
"parms" : {
"name" : "toron"
},
"count" : "1",
"cmd" : "SELECT * FROM tblTR WHERE (LEFT(`temple`, 5)='TORON') ORDER BY Temple LIMIT 40",
"temples" : {
"TORON" :
{
"idtr": 128,
"code": "TORON",
"code2": "",
"temple": "Toronto, ON, CA",
"address": "10060 Bramalea Rd, Brampton, ON L6R 1A1",
"templestart": 19900825,
"templeend": 99991231,
"used": 0,
"tag1": 0,
"qstag": 0
}
}
}
The member response.parms.name
of this object is the string that was entered by the user into an <input type="text">
that has templeChanged
as its change event handler. Since the response has a single match the value of that input field is replaced by the content of the temple
member of the first member of response.temples
.
{
"parms" : {
"name" : "A", "lang" : "en"
},
"count" : "8",
"cmd" : "SELECT * FROM tblTR WHERE (LEFT(`temple`, 1)='A') ORDER BY Temple LIMIT 40",
"temples" : {
"ABA" :
{
"idtr": 2,
"code": "ABA",
"code2": "",
"temple": "Aba, Nigeria",
"address": "",
"templestart": 20050807,
"templeend": 0,
"used": 0,
"tag1": 0,
"qstag": 0
},
"ACCRA" :
{
"idtr": 3,
"code": "ACCRA",
"code2": "",
"temple": "Accra, Ghana",
"address": "",
"templestart": 20040111,
"templeend": 0,
"used": 0,
"tag1": 0,
"qstag": 0
},
...
}
}
This response has multiple matches so the method prompts the user to choose one.