How do I use apis in AJAX?

0

Ajax will be used, but for the exam I have in a few hours they ask me to use ajax with some api and from there to get the information, I have no idea, can someone explain how I can do it? Thanks

    
asked by Fausto Jeje 31.05.2018 в 03:19
source

1 answer

1

An API is a web application that serves data to clients, almost equal to a web application that uses ajax.

You can use the test API of jsonplaceholder . For example, to get a list of post with ajax you just have to do the following:

function cargarPosts(){
  $.get("https://jsonplaceholder.typicode.com/posts", function(posts){
      console.log(posts);
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button onclick="cargarPosts()">Cargar posts</button>

There you get the list of posts and you can use that data to create a table with them.

    
answered by 31.05.2018 / 03:43
source