What I tend to do in this instance is keep all but config options in an 
external js file.
 
The at the top of my jsp (applicable to ASP as well) page I have a Global 
Config oject
 
var ApplicationConfig = {
    sessionId : <c:out value="${sessionId}" default:'null'/>,
    otherValue : <c:out value="${otherValue}" default:'null'/>,
}
 
Then in my sepearte JS file I can use these via ApplicationConfig.sessionId.  
It permits dynamic variables while keeping most of the Javascript off the page.
 

________________________________

From: jquery-en@googlegroups.com on behalf of MorningZ
Sent: Wed 10/12/2008 12:05
To: jQuery (English)
Subject: [jQuery] Re: Error getting value from server




"Actually my issue is that I am trying to keep my
html file neat and tidy by putting all my javascript code in a
separate js file"

Pick your poison:

- Use inline JS if you want dynamic variables
- Lose the dynamic variables if you want external JS

Your IIS server sees as request for ".js" (and ".css" and ".html" etc
etc) and passes it right back to the client as *plain text*, there is
no ASP processing applied to it





On Dec 10, 5:51 am, brian <[EMAIL PROTECTED]> wrote:
> This really ought to be asked on an ASP list but I'll try to explain.
>
> On Wed, Dec 10, 2008 at 3:48 AM, JQueryProgrammer
>
> <[EMAIL PROTECTED]> wrote:
>
> > Sorry for the spam. Actually my issue is that I am trying to keep my
> > html file neat and tidy by putting all my javascript code in a
> > separate js file.
>
> Believe me: sometimes ya gotta add some inline JS. I know, it's fugly.
>
> > But my javascript code refers to some server side
> > variable values which exists in an asp file. I have included that asp
> > file in my main asp file along with the js file. But the js file
> > dosn't seems to get server variable values. Here is a broad view of my
> > code.
>
> > mainpage.asp
> > ----------> <!--#include virtual = "/mywebsite/child1.asp" -->
> > ----------> <script type="text/javascript" src="child1.js"></script>
>
> > child1.asp
> > ----------> CONST myvar = 100
>
> Is it CONST or VAR? It's probably not worth sidetracking you at this point 
> but,
> anyway ...
>
> > child1.js
> > ----------> alert(<%= myvar%>);
>
> I think you need to step back and re-think this process. Your
> child1.js file is not read by
> the ASP interpreter. Thus, your <%= %> tags are meaningless therein.
> The only thing
> that reads that JS file is whatever browser that downloaded it. And
> its JS engine doesn't know
> or care about myvar.
>
> What you should be aiming for is to have ASP (on the server) write
> some text which will be
> sent to the browser where it will (hopefully) be interpreted by the
> browser's JS engine.
>
> So:
>
> child1.asp (let's say myservervalue = 'foobar')
> ---------------
>
> // this should look something like the following:
> // (is this even a real ASP comment?)
>
> <script type="text/javascript">
> var myvalue = "<%= myservervalue %>";
> </script>
> <script type="text/javascript" src="child1.js"></script>
>
> The ASP script will (again, hopefully) resolve the <%= myservervalue
> %> to some string. When the browser
> fetches the page its JS interpreter will see:
>
> var myvalue = "foobar";
>
> Accordingly, the page will now  have a variable named, "myvalue" which
> is, "foobar".
>
> child1.js
> ------------
>
> alert(myvalue);
>
> The variable that was declared is called, "myvalue" not "<%= myvalue
> %>". We're on the Javascript Ranch
> now. No need for the flappy tags. You should see a bright, shining
> "foobar" alert.
>
> If the page reaches the browser and it still has the <% %> business
> (view source), it's not working.



--------------------------------------------------------------------
This e-mail is intended solely for the addressee and is strictly confidential; 
if you are not the addressee please destroy the message and all copies. Any 
opinion or information contained in this email or its attachments that does not 
relate to the business of Kainos 
is personal to the sender and is not given by or endorsed by Kainos. Kainos is 
the trading name of Kainos Software Limited, registered in Northern Ireland 
under company number: NI19370, having its registered offices at: Kainos House, 
4-6 Upper Crescent, Belfast, BT7 1NT, 
Northern Ireland. Registered in the UK for VAT under number: 454598802 and 
registered in Ireland for VAT under number: 9950340E. This email has been 
scanned for all known viruses by MessageLabs but is not guaranteed to be virus 
free; further terms and conditions may be 
found on our website - www.kainos.com 


Reply via email to