How do I dynamically populate html elements with JSON Data with Javascript not jQuery?

后端 未结 7 1702
无人及你
无人及你 2020-12-24 09:46

I have this following JSON data snippit:

{\"items\": [
 {
   \"title\": \"sample 1\",
   \"author\": \"author 1\"
 },
 {
  \"title\": \"sample 2\",
  \"aut         


        
7条回答
  •  有刺的猬
    2020-12-24 10:01

    $(document).ready(function () {
        loadfunctionAjax();
    });
    var loadfunctionAjax = function () {
        $.ajax({
            type: 'GET',
            url: '/Site/SocialLink',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                var HTML = '';
                for (var i = 0; i < data.length; i++) {
                    item = data[i];
                    HTML += '
  • ' + item.Name + '
  • '; } $('#footerSocialNav').append(HTML); } }); }

提交回复
热议问题