全球主机交流论坛

标题: AJAX 求助 緊急!!!!!!!!!!!! [打印本页]

作者: CloudLink.asia    时间: 2016-6-19 22:17
标题: AJAX 求助 緊急!!!!!!!!!!!!
從Lab08_3a.php 拿資料在Lab08_3a.html的<tbody></tbody> 內顯示結果

Lab08_3a.php
  1. {"part":[{"item":"Motherboard","manufacturer":"ASUS","model":"P3B-F","cost":" 123.00"},{"item":"Video Card","manufacturer":"ATI","model":"All-in-Wonder Pro","cost":" 160.00"},{"item":"Sound Card","manufacturer":"Creative Labs","model":"Sound Blaster Live","cost":" 80.00"},{"item":" inch Monitor","manufacturer":"LG Electronics","model":" 995E","cost":" 290.00"}]}
复制代码


Lab08_3a.html
  1. <html>
  2. <head>
  3. <title>Lab08 Challenge Task</title>
  4. <link rel="stylesheet" href="Lab08_Q3_layout.css"/>
  5. <script src="/jquery/jquery-2.1.4.js"></script>
  6. <script>
  7. $(document).ready( function() {
  8.     (function() {
  9.         $.ajax({
  10.             type: 'POST',
  11.             url: 'http://localhost/lab08/Lab08_3a.php',
  12.             dataType: 'json',
  13.             success: function(result) {
  14.                xxxxxx
  15.             }
  16.         });
  17.     });
  18. });
  19. </script>
  20. </head>
  21. <body>

  22.         <h2>Table of Computer Parts</h2>
  23.         <table id="tableID" border="1">
  24.                 <thead>
  25.                         <tr>
  26.                                 <th>Item</th>
  27.                                 <th>Manufacturer</th>
  28.                                 <th>Model</th>
  29.                                 <th>Cost in $</th>
  30.                         </tr>
  31.                 </thead>
  32.                 <tbody>
  33.                        
  34.                 </tbody>
  35.         </table>
  36. </body>
  37. </html>
复制代码

作者: psdshow    时间: 2016-6-19 22:17
  1. $(document).ready( function() {
  2.     (function() {
  3.         $.ajax({
  4.             type: 'POST',
  5.             url: 'http://localhost/lab08/Lab08_3a.php',
  6.             dataType: 'json',
  7.             success: function(result) {
  8.                var part = result.part;

  9.                            var tbody = $('#tableID').find('tbody').eq(0);

  10.                            for(var i in part){
  11.                                         var _p = part[i];
  12.                                         var _html = '<tr><td>'+p.Motherboard+'</td><td>'+p.manufacturer+'</td><td>'+p.model+'</td><td>'+p.cost+'</td></tr>';

  13.                                         $(_html).appendTo(tbody);
  14.                            }
  15.             }
  16.         });
  17.     });
  18. });
复制代码

作者: CloudLink.asia    时间: 2016-6-19 22:30
psdshow 发表于 2016-6-19 22:22

還是不行
作者: CloudLink.asia    时间: 2016-6-19 22:40
psdshow 发表于 2016-6-19 22:22

(, 下载次数: 459)

能幫我看下嗎? 金幣給幾多都行 很趕急


作者: gger    时间: 2016-6-19 23:00
又上新项目了啊
作者: psdshow    时间: 2016-6-19 23:00
自己检查一下路径




欢迎光临 全球主机交流论坛 (https://443502.xyz/) Powered by Discuz! X3.4