Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use ASP in a JS include file?

Status
Not open for further replies.

altisdesign

Technical User
Apr 15, 2003
17
GB
Hi

I want to put code into a JS file, so that one code change will change all of the pages, and so each of my pages are more cleanly coded and the code isn't quite so obvious when you view source. However, the Javascript I want to put in the JS file involves ASP to load information out of a database. Can anyone think of a way for this ASP to still execute and the JS file to still be included? (I have thought of using SSI but this just puts the code in place, and it is not the same as a JS file). I don't know if this is possible however.

Many Thanks
-Altis Design
 
You would use 2 separate included files, 1 with the ASP code and 1 for the javascript.
The reason being that .js files are downloaded to the client browser cache for execution and .asp or .inc are executed by the server.
So having your javascript in a file with a .asp or .inc extension (as it would have to be to run the ASP code) would mean that the file would not be passed to the client browser but executed by the server.


Chris.


Indifference will be the downfall of mankind, but who cares?
 
But how would I include the ASP file in the JS file??

Many thanks for your response so far, I kind of get what you mean
-Altis Design
 
before I suggest another solution, what does the ASP page do that the server side jscript cannot do to retrieve the data from the database?
 
you cannot really include files in .js files
unless it is another .js page
we tried to include an asp page in an html page and could not ,
it would be a good idea to rename the file
e.g. file to a.asp
microsoft suggests that we name all web related files(.js,.htm and .html) to .asp even if there is no asp code as it is supposed to be faster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top