user3505775
user3505775

Reputation: 339

cannot find js file

I have stucture code like this:

enter image description here

I try to load javascript into php file like this:

enter image description here

But i have an error like this: enter image description here

This is my html : enter image description here

And this is another javascript:

enter image description here

And i try to copy paste the link, and i got an error 404 not found. How can i fix it? Thanks.

Upvotes: 4

Views: 28881

Answers (5)

burnah-boiii
burnah-boiii

Reputation: 5914

If you are developing locally, try clearing your cache.

Google Chrome likes to use the cached JavaScript files instead of the real ones.

Clearing your cache should resolve the issue.

Upvotes: 0

rinzler78
rinzler78

Reputation: 180

If you are referring to a file with path: /ui/new-file.js

then,

1.In html file include

<script type="text/javascript" src="/ui/new-file.js"></script>

2.In server.js or app.js whichever you have, include

app.get('/ui/new-file.js', function (req, res) {
  res.sendFile(path.join(__dirname, 'ui', 'login-file.js'));
});

Upvotes: 3

Irrech
Irrech

Reputation: 1394

In the html you can write *script** in the head or in the body, but not in your file js, delete this in fusionCharts.js

<script type=text/javascript>

In fusionCharts.js write only the function without the script

Upvotes: 0

Chris Middleton
Chris Middleton

Reputation: 5924

Permissions

When the host is correct, and the file is in the right place, and you have no other networking problems, you may sometimes still get a 404 because of bad file permissions. If a server does not have permission to access a file, it may send out a 404 error in response. The reason why some "Not Authorized" error is not given instead, is that this would reveal more information about the files than you, the owner of the server, may intend. The way to respond to requests for privileged files without revealing whether or not they exist is to give a 404.

On Windows, you can view and change the permissions from the File Explorer by right-clicking on the file or folder, then going to Properties -> Security -> Edit. For more information, see the notes on permissions on Microsoft's site.

File Types

Besides permissions, a server must also be configured to serve the type of file you are accessing. If files with different extensions are served, but .js files are not, check the configuration of your server to make sure that .js files aren't blacklisted (or not whitelisted, as the case may be).

Directory Location

You should also verify that the files are actually stored in the top-most directory of the web server if that's how you are accessing them. If they aren't, you may need to prefix the path with the path from the webserver root to your application directory. E.g., instead of fusioncharts/..., you may need /path/to/fusioncharts/... or ../../path/to/fusioncharts.

Other Considerations

In your particular case, you should also verify that the files inside the fusioncharts folder are actually structured the way you think. (E.g., is there really a js/[insert name here].js file inside the fusioncharts folder?

If none of that solves your problem, try to take something that is working and gradually make it more and more similar to the files that aren't working. By figuring out at which point you go from a working setup to a not working setup, you may discover the problem.

Upvotes: 5

Vajira Lasantha
Vajira Lasantha

Reputation: 2513

Assuming you are using codeigniter, you can use base_url() function to include JS files in your codeignitor view template file.

<script src="<?php echo base_url(); ?>fusioncharts/js/fusioncharts.js" type="text/javascript"></script>

codeigniter default view template is called welcome_message.php and this file is located in application/view folder.

This is how I include js files in my codeigniter projects. Hope this will help.

Upvotes: 2

Related Questions