1

The page loads up fine, but console shows a 404 not found error for JavaScript files. I have verified that the code contains the correct JavaScript file name. Any ideas?

The JavaScript file is loaded like this of course by HTML:

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

Environment: Windows 7; FastCGI; PHP. The instructions for installation came from this site:

http://www.microsoft.com/web/platform/phponwindows.aspx

I made a basic html file that looks like this:

<html>

<head></head>
<body>

hello again.
<div id="11">
hello
</div>
<script type="text/javascript" src="http://localhost/analyst_scrape/jquery.js"></script>

<script type="text/javascript">
$("#11").click(fucntion(){

    alert("good bye");
});

</script>
</body>
</html>

The html file gives me a blank page. However when i change the file ext to .php, I get the following error in console:

GET http://localhost/analyst_scrape/jquery.js 404 (Not Found) test.php:10
Uncaught ReferenceError: $ is not defined 
Lawrence DeSouza
  • 111
  • 1
  • 1
  • 5

1 Answers1

1

Looks like you are simply specifying the wrong path. You have not given any information about what you are actually doing so this is just speculation. You mention cgi/phpso I assume you are serving a page that generates the html by running a php script in the cgi/php directory under your page's root.

If that is the case, if the root of your page is foo, then the page you are viewing is in foo/cgi/php/ and your javascript file is probably in foo itself. Try specifying the correct path:

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

Or even the full URL:

<script type="text/javascript" src="http://www.foo.com/jquery.js"></script>
terdon
  • 52,568
  • 14
  • 124
  • 170
  • If I type in the url of the JS file, it gives a blank page in chrome. – Lawrence DeSouza Dec 18 '13 at 15:03
  • @LawrenceDeSouza please explain how your page is set up. A 40-4 error means the file was not found so you are using the wrong path. I can't tell you the right one unless you explain where your `index.php` or `index.html` file is, where your `js` is and where your `php` is. If you get a blank page then you might actually have a blank file. Is the `jquery.js` file really where you think it is? Is it empty? – terdon Dec 18 '13 at 15:08
  • No, the JS file is not empty. It is located in the same folder as the index.php file : http://localhost/folder_name/ – Lawrence DeSouza Dec 18 '13 at 15:17
  • @LawrenceDeSouza OK, does it work if you create a minimal `.html` file (not `php`) and point it to `jquery`? If chrome gives you a blank page then there _is_ a file but it is empty. – terdon Dec 18 '13 at 15:22
  • I made a simple html file, including the javascript, and a simple test function of the jquery. The html file gives a blank page. But when i make it a php file, I get the following error: Uncaught SyntaxError: Unexpected token { – Lawrence DeSouza Dec 18 '13 at 15:36
  • This was the code i put :
    hello
    – Lawrence DeSouza Dec 18 '13 at 15:38
  • 1
    @LawrenceDeSouza well, that just means you have a syntax error, you have `{` where you shouldn't. You really need to explain this more clearly. Please [edit] your question and give a minimal reproducible example. At the moment, we have to guess where your files are and what they look like. You need to set up the simplest possible case that gives you this error and provide us with everything necessary to reproduce it. – terdon Dec 18 '13 at 15:38
  • I gave you the example in the line above. The bracket is properly closed. – Lawrence DeSouza Dec 18 '13 at 15:45
  • 1
    @LawrenceDeSouza my comment was written before you posted yours. Please [edit] your question to add new info instead of placing it in comments, it is very hard to read. Also, if you are giving URLs, you will need to use `http://localhost/foo/jquery.js`. – terdon Dec 18 '13 at 15:49
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/12055/discussion-between-terdon-and-lawrence-desouza) – terdon Dec 18 '13 at 15:49