0

I'm trying to call a JSON API response and can't seem to displace the response on my website. Can anyone help me figure out what I'm doing wrong?

Updated:

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

 <script>
    $(document).ready(function(){ 

   $.getJSON("http://localhost:8080/animal/farm", function(data) {

      alert("hi");alert(data.data.writeLatencyMicro);
      alert(data.farm.horses);
      $("ConPerSec").html(JSON.stringify(data));       
   });
 });
</script>

...html

 <div id="ConPerSec">
 </div>

....

The JSON file comes back as {"farm":{"horses":"2", "cows":"5"}}

8
  • 1
    you didn't close window.onload functionw why? Commented Feb 28, 2014 at 8:16
  • I don't get it, does it output that string on the screen, or doesn't it output anything? Did you try chaining on a fail() to see if there are errors, such as same origin issues etc Commented Feb 28, 2014 at 8:17
  • And what's with the window.onload and the ancient jQuery version! Commented Feb 28, 2014 at 8:18
  • Oh, I'm super new at jquery. will look up the new functions. Commented Feb 28, 2014 at 8:19
  • If it's just the one item you are updating, I suggest you use id instead of class <div id="mydiv"> and then the jQuery $("#mydiv").html(JSON.stringify(data)) unless your intent was to update multiple items on your page that had the class 'ConPerSec' Commented Feb 28, 2014 at 8:23

1 Answer 1

1

If it will always be 1 object / row:

$.getJSON("http://localhost:8080/animal/house", function(data) {
         alert(data.farm.horses);
         alert(data.farm.cows);
});
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.