[jQuery] Re: Error getting value from server
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. 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 child1.js -- alert(%= myvar%); But alert is giving error. Please advice change in the code if any. I can put the alert code in mainpage.asp too, but that will make my asp page full of javascript functions. I want to keep mainpage.asp clean. Thanks for the response. On Dec 10, 12:25 pm, brian [EMAIL PROTECTED] wrote: Please keep your threads tidy. Don't spam the list with the same question. The file that contains the line: var myvalue = %= myservervalue%; ... is a .js file, right? It's been a long time, but I'm guessing the ASP interpreter isn't set by default to parse .js files. Put the line in the head of the HTML file you're creating (ie. your ASP script): script type=text/javascript var myvalue = %= myservervalue%; /script And it's really not a good idea to create your own attributes for HTML elements. Not unless you reference your own DTD and, even then, you're looking for trouble. On Wed, Dec 10, 2008 at 12:34 AM, JQueryProgrammer [EMAIL PROTECTED] wrote: I am migrating my existing ASP application javascript code to jquery. However places where i want to get the value from server, I am getting an error like: var myvalue = %= myservervalue%; when i check in myvalue, it is populated with %= myservervalue% as string. If I try to remove then it gives an error in comparison. Any help would be appreciated.
[jQuery] Re: Error getting value from server
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.
[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.
[jQuery] Re: Error getting value from server
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
[jQuery] Re: Error getting value from server
Please keep your threads tidy. Don't spam the list with the same question. The file that contains the line: var myvalue = %= myservervalue%; ... is a .js file, right? It's been a long time, but I'm guessing the ASP interpreter isn't set by default to parse .js files. Put the line in the head of the HTML file you're creating (ie. your ASP script): script type=text/javascript var myvalue = %= myservervalue%; /script And it's really not a good idea to create your own attributes for HTML elements. Not unless you reference your own DTD and, even then, you're looking for trouble. On Wed, Dec 10, 2008 at 12:34 AM, JQueryProgrammer [EMAIL PROTECTED] wrote: I am migrating my existing ASP application javascript code to jquery. However places where i want to get the value from server, I am getting an error like: var myvalue = %= myservervalue%; when i check in myvalue, it is populated with %= myservervalue% as string. If I try to remove then it gives an error in comparison. Any help would be appreciated.