html JS.JSON.AJAX.Request.Live编码视频,JSON与XhR2 API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html JS.JSON.AJAX.Request.Live编码视频,JSON与XhR2 API相关的知识,希望对你有一定的参考价值。

table {
  margin-top: 20px;
}
table, tr, td {
  border: 1px solid;
} 
  function search() {    
    // Send an XhR2 query. See HTML5 games and Apps MOOC at W3Cx
    // for detailed explanation about XhR2.
    var queryURL = "https://jsonplaceholder.typicode.com/users";
    
    var xhr = new XMLHttpRequest();
    xhr.open('GET', queryURL, true);
    
    xhr.onload = function(e) {
      var users = JSON.parse(xhr.response);
      
      displayUsersAsATable(users);
    }
    
    xhr.send();
    
} 
  
function displayUsersAsATable(users) {
     // users is a JavaScript object
  
    // empty the div that contains the results
    var usersDiv = document.querySelector("#users");
    usersDiv.innerHTML = "";
  
    // creates and populate the table with users
    var table = document.createElement("table");
  
    users.forEach(function(currentUser) {
      var row = table.insertRow();
      row.innerHTML = "<td>"+ currentUser.name+ "</td><td>" 
        + currentUser.email + "</td>";
    });
  
    usersDiv.append(table);
}

JS.JSON.AJAX.Request.Live coding video, JSON with the XhR2 API
--------------------------------------------------------------


A [Pen](https://codepen.io/Onlyforbopi/pen/OBLpLM) by [Pan Doul](https://codepen.io/Onlyforbopi) on [CodePen](https://codepen.io).

[License](https://codepen.io/Onlyforbopi/pen/OBLpLM/license).
<!DOCTYPE html>
<html lang="en">
<head>
<title>Working with remote data using XhR2</title>
  <meta charset="utf-8"/>
</head>
<body>
  <p>Working with remote data suing XhR2</p>
  <button onclick="search();">Get a remote list of users' names and emails</button>
  <div id="users"></div>
</body>
</html>


以上是关于html JS.JSON.AJAX.Request.Live编码视频,JSON与XhR2 API的主要内容,如果未能解决你的问题,请参考以下文章

Html.Partial 与 Html.RenderPartial 和 Html.Action 与 Html.RenderAction

html Html模板/ Html Boilerplate |标签HTML

html里怎么引用一个html的头部

html5与传统html区别

html4和html5的区别

HTML元素