最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - local js file not working - Stack Overflow

programmeradmin2浏览0评论

Okay I have a js file in htdocs and when I include it in my php page it doesn't work however when I load it from online it works I don't know what is wrong with it. I have:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> test</title>
</head>

I am putting the js file at the bottom of the page and this doesn't work,

<script type="text/javascript" src=".7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/boostrap.js"></script>
<script type="text/javascript" src="js/wpts_slider_multiple.js"></script>

This works,

<script type="text/javascript" src=".7.2/jquery.min.js"></script>
<script type="text/javascript" src=".js"></script>
<script type="text/javascript" src=".js"></script>

Okay I have a js file in htdocs and when I include it in my php page it doesn't work however when I load it from online it works I don't know what is wrong with it. I have:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> test</title>
</head>

I am putting the js file at the bottom of the page and this doesn't work,

<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="js/boostrap.js"></script>
<script type="text/javascript" src="js/wpts_slider_multiple.js"></script>

This works,

<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.jqueryslidershock./wp-content/plugins/tsslider/js/boostrap.js"></script>
<script type="text/javascript" src="http://www.jqueryslidershock./wp-content/plugins/tsslider/js/wpts_slider_multiple.js"></script>
Share Improve this question asked Oct 9, 2013 at 5:18 LmxcLmxc 2834 gold badges6 silver badges17 bronze badges 6
  • whichever browser your opening , just try checking in the JS/web console for errors.It will tell what exactly your problem is .For chrome its F12 to bring up the console – Mevin Babu Commented Oct 9, 2013 at 5:24
  • 1 Check in console and tell us what error you got there – Blu Commented Oct 9, 2013 at 5:27
  • @MevinBabu I am using Firefox. – Lmxc Commented Oct 9, 2013 at 5:28
  • I see ReferenceError: jQuery is not defined @ localhost/js/cloudzoom.js:5. Basically this is another file I don't know if it has something to do with this prob. – Lmxc Commented Oct 9, 2013 at 5:31
  • 1 if you include JQuery file it must be above all js files Best place for JQuery file is in head section – Blu Commented Oct 9, 2013 at 5:33
 |  Show 1 more ment

4 Answers 4

Reset to default 2

try this: src="/js/boostrap.js"> instead of src="js/boostrap.js">

the / is your root path

you can use this absolute path /js/boostrap.js in php, js, css files, and it works fine.

<script type="text/javascript" src="/js/boostrap.js"></script>
<script type="text/javascript" src="/js/wpts_slider_multiple.js"></script>

You should give full path of your jquery files like

http://example./js/boostrap.js

Code

<script src="http://example./js/boostrap.js"></script>
<script src="http://example./js/wpts_slider_multiple.js"></script>

Either of the following is happening.

Incorrect path - Please check the file paths.

No Read permission for the JS files - If you are sure that the path for the local JS files are correct, check their read permissions.

File does not exist - Simple reason as it states. I believe that it's not the case.

Let me know what you found.

try giving the paths like

<script type="text/javascript" src="/js/boostrap.js"></script>
<script type="text/javascript" src="/js/wpts_slider_multiple.js"></script>

src='/js/boostrap.js'

Assuming your root is http://localhost then the above link should always resolve to http://localhost/ProjectName/js/boostrap.js whether it's called from http://localhost/ProjectName/index.php or http://localhost/ProjectName/subdir/index.php

Make sure the js files are present within your folder structures

Always try to give relative paths to your files so that they can be easily found.

发布评论

评论列表(0)

  1. 暂无评论