Use $.ajax to receive JSON from API - Javascript jQuery

Javascript examples for jQuery:Json

Description

Use $.ajax to receive JSON from API

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script> 
  <script type="text/javascript">
    window.onload=function(){/*from   w  w w  . j a va 2  s  . com*/
$.get({
  url: 'http://your server/posts?filter[orderby]=rand&filter[posts_per_page]=1',
  success: function(data) {
    $('#output').html(JSON.stringify(data));
  }
});
    }

      </script> 
 </head> 
 <body> 
  <div id="output"> 
  </div>  
 </body>
</html>

Related Tutorials