resander
06-06-2009, 07:01 PM
I have an application that needs chunks of data from a server database, where a chunk contains an array of person records of people living at a particular place and data about the place. The javascript code contains logic for searching and displaying a chunk on the client. The server only provides chunk data on request from the client.
I am thinking of doing it like this (outlined):
<html>
...
<script id=dataid....>
var placename = "Dagenham";
var longitude = somevalue;
var latitude = somevalue;
var persons =["John Johnson" , ... "Carpenter",
.............
"Carla Karlsson" , ... "Teacher"
];
</script>
<script id=codeid..> (uses data in script section above and searches and displays a chunk)
function xyz() {....}
function zyx() {....}
</script>
...
<body>
(presentation and GUI elements here start/refine search and request new chunks)
...
</body>
AJAX XMLHttpReq will be used to request another chunk, e.g. data for Romford and the server would return different text data in the same format as above:
var placename = "Romford";
var longitude = othervalue;
var latitude = othervalue;
var persons =["Ben Benson" , ... "Retired",
.............
"Anne Andersson" , .. "Nurse"
];
The XMLHttpRequest callback function would call:
document.getelementbyid ( 'dataid').innerHTML = textdatareturnedbyXMLHttpreq;
Q1. is this approach going to work? or are there better ways?
Q2. is the 'old' dataid script element content automatically deleted when a new
value is set by innerHTML?
Q3. will textdatareturnedbyXMLHttpReq be parsed or prepared so that
the code script-section can refer to it?
I am thinking of doing it like this (outlined):
<html>
...
<script id=dataid....>
var placename = "Dagenham";
var longitude = somevalue;
var latitude = somevalue;
var persons =["John Johnson" , ... "Carpenter",
.............
"Carla Karlsson" , ... "Teacher"
];
</script>
<script id=codeid..> (uses data in script section above and searches and displays a chunk)
function xyz() {....}
function zyx() {....}
</script>
...
<body>
(presentation and GUI elements here start/refine search and request new chunks)
...
</body>
AJAX XMLHttpReq will be used to request another chunk, e.g. data for Romford and the server would return different text data in the same format as above:
var placename = "Romford";
var longitude = othervalue;
var latitude = othervalue;
var persons =["Ben Benson" , ... "Retired",
.............
"Anne Andersson" , .. "Nurse"
];
The XMLHttpRequest callback function would call:
document.getelementbyid ( 'dataid').innerHTML = textdatareturnedbyXMLHttpreq;
Q1. is this approach going to work? or are there better ways?
Q2. is the 'old' dataid script element content automatically deleted when a new
value is set by innerHTML?
Q3. will textdatareturnedbyXMLHttpReq be parsed or prepared so that
the code script-section can refer to it?