1

I have a simple javascript file like so:

$(document).ready(function () {
    alert("my controller");
});

I have an HTML file like so:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript" src="/js/generateLineupController.js"></script>
</body>
</html>

for the love of all things holy why in the world would the alert not show? I get a 200 on GET for the javascript file, so it's loading.

3
  • Is there a reason you have a node.js tag on this question? It's distracting me from answering your question because I'm waiting to hear about how node is involved :) Commented Dec 21, 2014 at 5:06
  • yeah, crap, I am using browserify to load node modules, I thought I might take this question in that direction, but I can remove the tag Commented Dec 21, 2014 at 5:13
  • I copied the code as it is (now ;)) in this question and got the alert. Are there other scripts being loaded, or some kind of NoScript-type plugin? Commented Dec 21, 2014 at 5:30

2 Answers 2

4

Several problems here.

  1. You're trying to load the script twice for some reason. Don't do that. Load it in <head>, or at the end of <body>, but not both.

  2. You're trying to use jQuery syntax ($(...)), but you haven't loaded the jQuery library. You'll need that.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, I forgot to add the jquery library for my OP, but I have it my actual code, and that's not the problem
2

The $(document).ready(...) indicates that you are trying to use jQuery, but you aren't loading jQuery in your page. Check your console log; you will see the errors there.

Also, there's no need to load the script twice with two <script> tags; just load it once.

3 Comments

thanks Ed please see my edits, the missing jquery library is not the problem (nor was the double loading of the script).
Are you running this on a server? Or are you just opening the doc in a browser with a local file path for a URL? If the latter, the relative src will cause problems. Also, are you sure you haven't checked don't show any more alerts for this page or anything similar in your browser?
it works, when I ran the one file alone, it wasn't pulling in my javascript file. The problem I have has to do with browserify. oh well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.