dcsimg
retrieving string from xml created in php with variables to be used from javacsript file.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   pire_naq
Posted On:   Thursday, September 7, 2006 05:04 AM

I am retrieving a string with a lot of redundant information to set the inner HTML of a layer.

I had thought that if I had a javascript string variable representing the data, I would be able to include a variable in the string so that it includes the information when inserting the innerHTML.


So Basically, if "Ask Ajax question" came out in the string a lot, have a javascript string variable sd = "ask ajax question" and in the string in the xml have the innerHTML+sd+moreinnerHTML so that the xml file is reduced in file size.

Would this be possible? I haven't been able to implement it yet. thanks in advance

Re: retrieving string from xml created in php with variables to be used from javacsript file.

Posted By:   murali_sappa  
Posted On:   Friday, September 15, 2006 06:45 PM

Yes, it is possible - however, not as you specified. If you have the following string - 
abcd efgh ijkl
and you want to replace "efgh" by "somethingelse" and if you have a javascript variable global/local that is defined as -
var efgh="somethingelse";
Then, you need to to return the following string from your server -
"abcd "+efgh+" ijkl"
And, set your innerHTML with eval(stringreturned)

Basically, you are forcing the browser to expand the javascript variables since that can't be done on the sever side. This option is will have a variety of side effects :) so, unless you really need to go this route, don't do it.

Few other options would be to parse the returned data and modify before setting the innerHTML, use regular expressions, or use defer tag and return the data as javascript. Hope this information helps, please let us know what you find.

Regards,
-Murali
About | Sitemap | Contact