0

Trying to learn some basic javascript and api usage. Trying to get some weather information from Open Weather Map but none of the alert or console.log requests are being reported by the browser (Chrome).

    <script type="text/javascript" src="jquery-3.2.1.min.js">
    alert("this works first maybe");
    console.log("HEEEELLLLOOOOO");
        $(document).ready(function(){
            var i = 0;
            getJson();

            function getJson() {
                    console.log("getting data now");
                    $.getJSON("openweatherlink");
            }
        });
    </script>
5
  • 1
    Please use a more explicit title. There are 1.4m questions about JavaScript, luckily they do not all have a title of this kind Commented Aug 3, 2017 at 12:33
  • @user3547778 stackoverflow.com/help/dont-ask Commented Aug 3, 2017 at 12:35
  • I thought it was a big vague when writing it. Ill learn. Commented Aug 3, 2017 at 12:37
  • This same code is working in mine machine. Probably it might be problem with your jquery import or project setup. I am using 1.12.5 version of jQuery. Commented Aug 3, 2017 at 12:45
  • @user3547778 Please consider marking one of the answers as a solution if any of those solved your problem. If you still have a problem with the current question, please let us know Commented Oct 17, 2017 at 11:04

3 Answers 3

11

You can not use src in a <script> that contains code.

Use

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
    Your code
</script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
  alert("this works first maybe");
  console.log("HEEEELLLLOOOOO");
  $(document).ready(function() {
    var i = 0;
    getJson();

    function getJson() {
      console.log("getting data now");
      $.getJSON("openweatherlink");
    }
  });
</script>

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

3 Comments

Its always the simple things. Any advice for trying to troubleshoot these problems solo or are these type of hiccups un-avoidable? :)
Basic its learn by mistakes, No one in here can say they never made any code mistakes. I don't think there is any "direct" way to troubleshoot problems, except stay cool and take it 1 step at the time
@user3547778 Do you still have problems with this question?
0

You code should be like below.

First script tag should contain jQuery import statement.

Second script tag in which you can write jQuery/javascript code.

<script src="jquery-1.x-git.min.js" type="text/javascript"></script>
<script>
    alert("this works first maybe");
    console.log("HEEEELLLLOOOOO");
    $(document).ready(function () {
        var i = 0;
        getJson();

        function getJson() {
            console.log("getting data now");
            $.getJSON("openweatherlink");
        }
    });
</script>

Comments

0
<script type="text/javascript" src="jquery-3.2.1.min.js">
<script>
    $(document).ready(function(){
        alert("this works first maybe");
        console.log("HEEEELLLLOOOOO");
        var i = 0;
        getJson();
    });
    function getJson() {
         console.log("getting data now");
          $.getJSON("openweatherlink");
    }
</script>

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.