最新的Web開發教程
 

W3Data的Http


此頁上的實施例相同的上頁的實施例中,除了將數據從web服務器請求: customers.php


灌裝下拉

<select id="id01">
<option w3-repeat="customers">{{CustomerName}}</option>
</select>

<script>
w3Http("customers.php", function () {
    if (this.readyState == 4 && this.status == 200) {
        var myObject = JSON.parse(this.responseText);
        w3DisplayData("id01", myObject);
    }
});
</script>
試一試»

填充列表

<ul id="id01">
  <li w3-repeat="customers">{{CustomerName}}</li>
</ul>

<script>
w3Http("customers.php", function () {
    if (this.readyState == 4 && this.status == 200) {
        var myObject = JSON.parse(this.responseText);
        w3DisplayData("id01", myObject);
    }
});
</script>
試一試»

填寫表

<table id="id01">
  <tr>
    <th>Customer</th>
    <th>City</th>
    <th>Country</th>
  </tr>
  <tr w3-repeat="customers">
  <td>{{CustomerName}}</td>
  <td>{{City}}</td>
  <td>{{Country}}</td>
  </tr>
</table>

<script>
w3Http("customers.php", function () {
    if (this.readyState == 4 && this.status == 200) {
        var myObject = JSON.parse(this.responseText);
        w3DisplayData("id01", myObject);
    }
});
</script>
試一試»

灌裝另一個表

<table id="id01">
  <tr>
    <th>Title</th>
    <th>Artist</th>
    <th>Price</th>
  </tr>
  <tr w3-repeat="cd">
  <td>{{title}}</td>
  <td>{{artist}}</td>
  <td>{{price}}</td>
  </tr>
</table>

<script>
w3Http("customers.php", function () {
    if (this.readyState == 4 && this.status == 200) {
        var myObject = JSON.parse(this.responseText);
        w3DisplayData("id01", myObject);
    }
});
</script>
試一試»