How to append objects from JSON to a div in HTML? How to append objects from JSON to a div in HTML? json json

How to append objects from JSON to a div in HTML?


Firstly the parameter you define in the $.ajax callback is data, not datas and the properties you're trying to access are in the form object of the response, so you need to use data.form to access them.

Lastly, and most importantly, you need to concatenate the HTML string you create together with the values from the retrieved object. Try this:

$(document).ready(function() {  var datas = $.get("https://api.github.com/users/iwenyou", function(infos) {    $.ajax({      type: "POST",      url: "https://httpbin.org/post",      data: infos,      dataType: "json",      success: function(data) {        $(".container").append('<div>' + data.form.avatar_url + '</div><div>' + data.form.login + '</div><div>' + data.form.name + '</div>');      }    });  });});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div class="container"></div>