-1

Hi i am currently working on a small project where I am supposed to query a JSON API with the format

{
  "results": [
    {
      "livingstd": "80%",
      "place": "ClassA"
    },
    {
      "livingstd": "50%",
      "place": "ClassC"
    }
    ...
  ]
}

I am supposed to show the livings td whenever i hover over to a mini house icon.

so i wrote a javascript but it doesnt work. and I dont understand what went wrong. Can anyone shed some light on this? It doesn't show anything at all

<script type="text/javascript" src="js/function1.js"></script>
    <script>
    $(document).ready(function (e) {

        //api url
        var url = "dummyurl";
        //store search term
        var query;

        //when the user hover over
        $("button").hover(function (e) {
            //get value and store in variable
            query = $("#query").val();
            //get the json file
            $.getJSON(url + query, function (json) {
                $.each(json.results, function (i, occupancy) {
                    $("results").append('<p>' + occupancy.occupancy + 'at' + occupancy.time + '</p>')
                });
            });
        });
    });

</script>
4
  • Open your debugging tools and check if any error occur Commented Aug 12, 2014 at 6:33
  • @Se0ng11 what are debugging tools...? Commented Aug 12, 2014 at 6:41
  • Add your inline javascript to another script tag and edit your question and add more info Commented Aug 12, 2014 at 6:43
  • debugging tools is the tools for you to debug your js script easily, which come together with latest version of any web browser you had, by pressing f12(default key), a console with rich information of your page will appear, and you can easily see if any error in the console network tab, put a debugger; in your code while the debugging console open will let you to debug your js script easily, and this will ease us to troubleshoot your issue, your question are too broad which hard for us to troubleshoot Commented Aug 12, 2014 at 6:46

1 Answer 1

1

Did you look at the line that reads var url = "dummyurl";?

Also look at if your url and query are properly separated by a /. You can add query vars with '?' + $.param(queryObj).

Also if you look at the docs for hover, only giving one handler to hover means it gets called on mouseenter and mouseleave. Although that shouldn't prevent your code from working.

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

Comments

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.