2016-11-04 24 views
-2

データベースからデータを取得し、PHPのjqueryを使用してhtmlテーブルにバインドしようとしています。結果は正しく表示されます。しかし、私は取得されたデータが編集可能でなければならないことを意味する内部テキストボックスにデータをフェッチしたい。私の必要をしてください。データベースからデータを取得し、PHPのjqueryを使用してhtmlテーブルにバインド

マイコードです。

$.ajax({ 

      type: "POST", 
      url: "add_temp_purchase", 
     cache: false, 
     data: 'itemnum='+itemnum+'&quantity='+quantity+'&customer_id='+customer_id, 
     dataType: "html", 
     success: function(returnhtml) { 
      //alert(customer_id); 
       $.ajax({ 

       type: "GET", 
       url: "gettempid", 
       cache: false, 
       data: 'customer_id='+customer_id, 
       dataType: "html", 
       beforeSend: function() { 
                        $('#metable').html('loading please wait...'); 
                          }, 
         success: function(htmldata) { 
       var order_id = order_id; 
        var customer_id = customer_id; 
        var item_id = itemnum; 
        var count = quantity; 

       alert(customer_id); 


       $(".metable").find('tbody').append('<tr><td>' + order_id + 
       '</td><td><input type="text">' + customer_id + 
         '</td><td><input type="text">' + item_id + 
       '</td><td><input type="text">' + count + 
        '</td></tr>'); 


         } 
         }); 

私のhtmlコードは次のとおりです。

<table class="table table-striped table-hover metable table-bordered" id="editable-sample"> 
           <thead> 
           <tr> 
        <th>Id</th> 
            <th>Customer Id</th> 
            <th>Item Number</th> 
            <th>Quantity</th> 

           </tr> 
           </thead> 
           <tbody> 
           <?php 
     foreach ($tempresults as $result) 
       { 
       ?> 
           <tr class=""> 
      <td><input type="text" name="order_id" id="order_id" value="<?php echo $result->order_id;?>"></td> 
      <td><input type="text" name="customer_id" id="customer_id" value="<?php echo $result->customer_id;?>"></td> 
      <td><input type="text" name="item_id" id="item_id" value="<?php echo $result->item_id;?>"></td> 
     <td><input type="text" name="count" id="count" value="<?php echo $result->count;?>"></td> 

           </tr> 

           <?php 
      } 
        ?> 
           </tbody> 
          </table> 
                   Thanks, 
+0

、 '$(「#のORDER_ID」)を実行して、テキストフィールドの各値を設定するのval(result.correspondingdata);'(あなたがデータを返したことを想定しアレイ)。 –

答えて

0

これが最もエレガントな解決策ではないかもしれないが、あなたはこれを試してみたのですか?あなたのAjaxの返されるデータには

$(".metable").find('tbody').append('<tr> 
    <td><input type="text" value="' + order_id + '"></td> 
    <td><input type="text" value="' + customer_id + '"></td> 
    <td><input type="text" value="' + item_id + '"></td> 
    <td><input type="text" value="' + count + '"></td> 
</tr>');