0

I am trying to have have a user click a button to check the status of something via API. What am I doing wrong?

HTML:

<button onclick="myFunction('http://example.com/api')">Try it</button>

JS:

<script>
    function myFunction(url) {
        $.get(url, function (jQuery.parseJSON(result)) {
            alert(result.status);
        });
    }
</script>
user2270029
  • 871
  • 14
  • 27

1 Answers1

0

Following worked for me. I tested it my self. For details please see http://api.jquery.com/jQuery.get/

I used a test url like following:

<button onclick="myFunction('https://api.github.com/users/mralexgray/repos')">Try it</button>

Your function should look like following:

   function myFunction(url) {

       $.get(url, function (data) {
           var temp = data[0]
           alert("Data Loaded: " + data);
           alert("temp.id = " + temp.id);
           alert("temp.name = " + temp.name);
       });
   }
ATHER
  • 3,254
  • 5
  • 40
  • 63