rkt
rkt

Reputation: 1181

Error when trying to include several JS-files from within a JS-file

In a html file , inside the body tag I've these lines of code

<script type="text/javascript" src="http://xxx.com/js/publisher/promo.js"></script>

and in the promo.js file, I've put these lines

<script type="text/javascript" src="/js/jquery-1.3.2.min.js?v=5-5-09"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="/js/lazyload.js"></script>

and I get a javascript error(missing ; before statement) on the second line of promo.js file when I load the html file in the browser. Any ideas on why this is happening ?

Upvotes: 1

Views: 139

Answers (3)

Christofer Eliasson
Christofer Eliasson

Reputation: 33865

The problem is that you put HTML-tags in a file that you have specificed to contain JavaScript, with your type="text/javascript" attribute.

Upvotes: 2

Tejs
Tejs

Reputation: 41256

JavaScript files do not recognize HTML text.

In your promo.js file, if you have that text in it, that is not valid javascript.

If you want to include additional scripts from your javascript file, you will need to dynamically add javascript file references.

Upvotes: 2

Interrobang
Interrobang

Reputation: 17454

You cannot include scripts in the manner you're attempting to. You will either need to use a server-side script to dynamically create this bundle, or just put those three script includes right into your page.

Secondly, stop including two copies of jQuery; you only need one. You might want to update it as well, we're on 1.7.1 now.

Finally, <script> includes should go in the <head>, not the <body>.

Upvotes: 2

Related Questions