Karl Michael Linantud
Karl Michael Linantud

Reputation: 127

JS file not working CodeIgniter

So yeah here I am after searching for quite sometime, I said myself that it's time to post instead...

I've got CodeIgniter on my localhost and I am using WAMP server.

I have put this in constants.php

define('URL','http://localhost/ci/');
define('IMG',URL.'assets/images/');
define('CSS',URL.'assets/css/');
define('JS',URL.'assets/js/');

Then, I put it in my view site_header.php

<script type="text/javascript" href="<?php echo(JS.'custom.js'); ?>"></script>

and on the page source the ouput HTML syntax is correct,

<script type="text/javascript" href="http://localhost/ci/assets/js/custom.js"></script>

also, when I go the the link it displays the inside of the js file,

alert('Hello, this should work!');

BUT, unfortunately, I am not receiving the alert. I am really new to CodeIgniter, I just installed it few days ago, and It would really be helpful if anyone could answer me.

Thanks.

Upvotes: 1

Views: 1437

Answers (2)

Shafqat Jan
Shafqat Jan

Reputation: 11

Try to put like this <script src="<?php echo(URL.JS.'custom.js'); ?>"></script>

Upvotes: 0

Karl Michael Linantud
Karl Michael Linantud

Reputation: 127

should edit href to src

<script href="<?php echo(JS.'custom.js'); ?>"></script>

into

<script src="<?php echo(JS.'custom.js'); ?>"></script>

Upvotes: 1

Related Questions