Javascript in ASP
Results 1 to 7 of 7

Thread: Javascript in ASP

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    472

    Javascript in ASP

    I know this isn't the right place for this kind of question but I'll try my luck......

    In HTML there is a way to include a file containing javascript like this: <SCRIPT type="text/javascript" src="thescript.js"></SCRIPT>. This will reduce download overhead if many pages contain the same scripts, you won't have to download the scripts every time. Instead the browser will find the "thescript.js"-file in the cache.

    My problem is that I have to implement this in ASP. The javascript is the same for many of the pages, but it has to be genereated. So the file has the extension .asp (thescript.asp). If I try to include this file (SCRIPT type="text/javascript" src="thescript.asp"></SCRIPT>), i get an error-message.

    There is no way I can make the javascript static, it has to be genereated. But still the download overhead has to be reduced..... Anybody got a solution?

    Thanks in advance!
    ---
    proactive
    Share on Google+

  2. #2
    Senior Member
    Join Date
    Sep 2001
    Posts
    310
    Good question. From my knowledge '<SCRIPT type="text/javascript" src="thescript.js"></SCRIPT>' only applies to 'javascripts'. Therefore you would probally have to change the text/javascript to text/asp (only a guess) and that should work. The reason why you keep getting error messages is probally because the browser is trying to read a javascript file, but instead is getting a file that is written in asp. Thus it can't read it and returns error messages. I might have to try this one out and ask around. But I hope this helps.
    You could always use generator for flash, which also returns dynamic contents, and i also find that very easy to use.
    Share on Google+

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    472
    Hmm, I changed 'text/javascript' to 'text/asp', and it didn't work. I still get a 'object expected' error.
    ---
    proactive
    Share on Google+

  4. #4
    PHP/PostgreSQL guy
    Join Date
    Dec 2001
    Posts
    1,164
    ASP baaaaad, PHP/CGI/Perl goooooood!

    Nah, whatever works for you! Hmm...I'm not sure how ASP works at all, but maybe it's looking for a valid ASP file instead (in the src section) and is getting something that isn't ASP, hence the Object Expected error. This may or may not have any helpful relevance at all, but I know java is similar. Feel free to laugh in my general direction...
    We the willing, led by the unknowing, have been doing the impossible for the ungrateful. We have done so much with so little for so long that we are now qualified to do just about anything with almost nothing.
    Share on Google+

  5. #5
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,255
    Instead of using <script type="text/javascript" src="whatever.asp"> try <script language="javascript" src="whatever.asp"> and see if that works...

    If worst comes to worst, just write an include file that has a function that writes the output of the Javascript dynamically.
    Chris Shepherd
    The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
    \"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
    Is your whole family retarded, or did they just catch it from you?
    Share on Google+

  6. #6
    Senior Member
    Join Date
    Nov 2001
    Posts
    472
    I haven't found a solution yet..... But I'll let you know when I do. Pretty soon, I hope
    ---
    proactive
    Share on Google+

  7. #7
    Senior Member
    Join Date
    Nov 2001
    Posts
    472
    I finally found the solution to my problem. Here it is:

    code for file.asp:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    <SCRIPT LANGUAGE="JavaScript" SRC="filejs.asp"></SCRIPT>
    </HEAD>
    <BODY onload="return onLoad();">
    </BODY>
    </HTML>

    code for filejs.asp:
    <%@ Language=VBScript %>
    Response.ContentType = "application/x-javascript"
    Response.Expires = 4000
    %>

    function onLoad()
    {
    alert("hi all") ;
    }

    --

    It's the 'response.contenttype' that does the trick. It fools the broweser into believing the .asp file is a .js file. The response expires tells the server only to upload the file every 4000 minutes.
    ---
    proactive
    Share on Google+

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •