C
Chuck Anderson
I currently use an HTTP request object (with Php in the server) to
dynamically load HTML into document objects on a page. I do it one of
two ways.
1. I make a request to the server and my Php script returns JavaScript
variables. The returned variables are examined in JavaScript and based
on their value some element (object) on the page is (or is not)
changed. I use what may be a crude method to return variables. Php
echoes a string of the form "var varname1='some value';var
varname2='some other value';". Then in the JavaScript that receives
the HTTP request I merely eval(req.ResponseText). The script can then
make program decisions based on the values of the variables.
2. If a lot of HTML must be inserted/changed, I have the Php script
output the whole block of HTML. Then in the JavaScript that handles the
HTTP request I merely set the appropriate object's innerHTML to
http.responseText (obj.innerHTML = http.responseText).
These two methods have been working well for me.
I find now, though, that I would like to return a block of HTML and some
JavaScript variables via one HTTP request and I can not figure out how
(or if it's even possible) to do it.
(I tried returning the block of HTML as a string variable (converting
all single quotes in the HTML to the html entity "'"), but have had
no luck doing so. I believe that eval can not handle the line feeds.)
The whole point of returning a block of HTML as the http.responseText is
to avoid having to create a lot of complicated HTML within JavaScript
with all of it's necessary escapes (quotes), line feeds, and
concatenation characters. I accomplish this quite nicely with Php and
an included file.
I could simply make two HTTP requests; one to retrieve the variables,
and a second to retrieve the "large" block of HTML, but I thought it
would make sense to try and limit the number of network requests made by
the script.
Is there a method for achieving what I want to do?
Would it make sense to try and return the data in XML format instead of
text - with the HTML block in an XML element - along with any other
variables in heir respective elements?
Or should I merely keep making two requests; one to get variables and
then issue another if I need to retrieve a large block of HTML?
I would appreciate any advice.
TIA
--
*****************************
Chuck Anderson • Boulder, CO
http://www.cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
dynamically load HTML into document objects on a page. I do it one of
two ways.
1. I make a request to the server and my Php script returns JavaScript
variables. The returned variables are examined in JavaScript and based
on their value some element (object) on the page is (or is not)
changed. I use what may be a crude method to return variables. Php
echoes a string of the form "var varname1='some value';var
varname2='some other value';". Then in the JavaScript that receives
the HTTP request I merely eval(req.ResponseText). The script can then
make program decisions based on the values of the variables.
2. If a lot of HTML must be inserted/changed, I have the Php script
output the whole block of HTML. Then in the JavaScript that handles the
HTTP request I merely set the appropriate object's innerHTML to
http.responseText (obj.innerHTML = http.responseText).
These two methods have been working well for me.
I find now, though, that I would like to return a block of HTML and some
JavaScript variables via one HTTP request and I can not figure out how
(or if it's even possible) to do it.
(I tried returning the block of HTML as a string variable (converting
all single quotes in the HTML to the html entity "'"), but have had
no luck doing so. I believe that eval can not handle the line feeds.)
The whole point of returning a block of HTML as the http.responseText is
to avoid having to create a lot of complicated HTML within JavaScript
with all of it's necessary escapes (quotes), line feeds, and
concatenation characters. I accomplish this quite nicely with Php and
an included file.
I could simply make two HTTP requests; one to retrieve the variables,
and a second to retrieve the "large" block of HTML, but I thought it
would make sense to try and limit the number of network requests made by
the script.
Is there a method for achieving what I want to do?
Would it make sense to try and return the data in XML format instead of
text - with the HTML block in an XML element - along with any other
variables in heir respective elements?
Or should I merely keep making two requests; one to get variables and
then issue another if I need to retrieve a large block of HTML?
I would appreciate any advice.
TIA
--
*****************************
Chuck Anderson • Boulder, CO
http://www.cycletourist.com
Turn Off, Tune Out, Drop In
*****************************