2016-06-14 115 views
-1

任何人都可以幫我創建一個Ajax請求這種情況?我想如果我點擊確定ID。我只想更新它的內容並存儲在數據庫中。希望這裏的任何人都能幫助我。謝謝。使用jQuery的AJAX POST請求

瀏覽文件:

<tbody> 
    <?php foreach ($ds_name as $dsname): ?> 
    <tr> 
     <td><div class="text-infoo<?= $dsname->id ?>"><?= $dsname->name ?></div></td> 
     <td> 
      <a href="#" id="edit<?= $dsname->id ?>"><span class="glyphicon glyphicon-pencil"></span></a> 
      <a href="#" id="ok<?= $dsname->id ?>"><span class="glyphicon glyphicon-ok"></span></a> 
      <a href="#"><span class="glyphicon glyphicon-remove"></span></a> 
     </td> 
    </tr> 
    <?php endforeach; ?> 
</tbody> 

<?php foreach ($ds_name as $dsname): ?> 
    $('#edit<?= $dsname->id ?>').click(function() { 
     var text = $('.text-infoo<?= $dsname->id ?>').text(); 
     var input = $('<input id="attribute<?= $dsname->id ?>" type="text" data-id="<?php echo $ds_content->id; ?>"value="' + text + '" />'); 
     $('.text-infoo<?= $dsname->id ?>').text('').append(input); 
     input.select(); 

     input.blur(function() { 
      var text = $('#attribute<?= $dsname->id ?>').val(); 
      $('#attribute<?= $dsname->id ?>').parent().text(text); 
      $('#attribute<?= $dsname->id ?>').remove(); 
     }); 
     $('#edit<?= $dsname->id ?>').hide(); 
     $('#ok<?= $dsname->id ?>').show(); 
    }); 
<?php endforeach; ?> 

回答

0

您可以通過此

$.ajax({ 
      url: "data.php",//file wich has query select to db table 
      data: {id:theid},//describe your data here 
      dataType: 'json',// type of data that will you get (JSON/HTML). 
      type: 'POST',//sending type (POST/GET) 
      success: function(data) { 
       //do change the select option 
      } 
     }); 

古德勒克做到這一點!