Jighead
2/1/2017 - 11:52 AM

Consume Rest API with jQuery

Consume Rest witj jQuery

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

<script>
$(document).ready(function() {     
  $.ajax({         
    url: "http://rest-service.guides.spring.io/greeting"     
    }).then(function(data) {        
      $('.greeting-id').append(data.id);        
      $('.greeting-content').append(data.content);     
    }); 
});
</script>



<!DOCTYPE html>
<html>
    <head>
        <title>Hello jQuery</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script src="hello.js"></script>
    </head>

    <body>
        <div>
            <p class="greeting-id">The ID is </p>
            <p class="greeting-content">The content is </p>
        </div>
    </body>
</html>