Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  53] [ 6]  / answers: 1 / hits: 19312  / 15 Years ago, fri, june 12, 2009, 12:00:00

I have the following script element in my web page:



<script src=default.js type=text/javascript></script>


Using JavaScript, I want to be able to retrieve the content of the script file. I know I could use an ajax request to get the data but then I am getting something from the server that I already have locally.



So what I would prefer to do is retrieve the content from the DOM (if that's possible) or something that has the same result.



Cheers
Anthony



UPDATE



I was trying to simplify the question, maybe a bad a idea, I thought this way would cause less questions.



The real situation I have is as follows, I actually have



<script type=text/html class=jq-ItemTemplate_Approval>
...
html template that is going to be consumed by jQuery and jTemplate
...
</script>


Now this works fine but it means each time the page loads I have to send down the template as part of the HTML of the main page. So my plan was to do the following:



<script src=template.html type=text/html></script>


This would mean that the browser would cache the content of template.html and I would not have to send it down each time. But to do this I need to be able to get the content from the file.



Also in this case, as far as I know, requesting the content via ajax isn't going to help all that much because it has to go back to the server to get the content anyway.


More From » html

 Answers
111

I think what you want to do is to assign a variable inside template.js. Then you have the variable available for use wherever you want in jquery. Something like:



var tpl = <div> ... </div>


Wouldn't this be a simpler solution to your problem? We do this in Ext JS. I think this will work for you in jQuery.


[#99330] Sunday, June 7, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;