2016-12-07 73 views
1

我目前正在製作一個可排序的表,並且需要將更多的id傳遞給序列化數組。如何將自定義變量添加到jQuery可排序?

我添加了所有我的代碼exept後文件,該dossent relly做任何事情比var_dumping張貼。

<!DOCTYPE html> 
<html lang="en"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> 
</head> 
<body> 
<div class="container"> 
    <div class="row"> 
     <div class="col-md-12"><br><br><br><br> 
      <table class="display table table-striped table-hover table-bordered dt-responsive responsive nowrap" cellspacing="0" width="100%"> 
      <thead> 
       <th>Navn</th> 
       <th>Order</th> 
      </thead> 
      <tbody id="sortable"> 
       <tr id="order_1" data-extravalue="45"> 
        <td>value</t> 
       </tr> 
       <tr id="order_2" data-extravalue="56"> 
        <td>value</t> 
       </tr> 
      </tbody> 
      </table> 
     </div> 
    </div> 
</div> 
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
<script type="text/javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 

     $('#sortable').sortable({ 
      update: function(event, ui) { 

       var order = $("#sortable").sortable('serialize'); 

       $.ajax({ 
        data: order, 
        type: 'POST', 
        url: 'post.php' 
       }); 
      } 
     }); 
    }); 
</script> 
</body> 
</html> 
+0

首先,你應該正確地關閉你''​​標籤:'​​'。其次,你想收集哪些其他信息? – Twisty

回答

1

不確定,但這可能會幫助你。由於您發佈到PHP,因此您需要使用json_decode(),電話號碼爲$_POST['json']

工作實例:https://jsfiddle.net/Twisty/a2e9626L/4/

HTML

<div class="container"> 
    <div class="row"> 
    <div class="col-md-12"> 
     <br> 
     <br> 
     <br> 
     <br> 
     <table class="display table table-striped table-hover table-bordered dt-responsive responsive nowrap" cellspacing="0" width="100%"> 
     <thead> 
      <th>Navn</th> 
      <th>Order</th> 
     </thead> 
     <tbody id="sortable"> 
      <tr id="order_1" data-extravalue="45"> 
      <td>value</td> 
      </tr> 
      <tr id="order_2" data-extravalue="56"> 
      <td>value</td> 
      </tr> 
     </tbody> 
     </table> 
    </div> 
    </div> 
</div> 

的JavaScript

$(function() { 
    $('#sortable').sortable({ 
    update: function(event, ui) { 
     var order = $("#sortable").sortable('serialize'); 
     var data = []; 
     $("#sortable tr").each(function(i, el) { 
     data.push({ 
      order: $(el).attr("id"), 
      value: $(el).data("extravalue") 
     }); 
     }); 
     $.ajax({ 
     data: { 
      json: JSON.stringify(data) 
     }, 
     type: 'POST', 
     url: 'post.php' 
     success: function(d) { 
      console.log(d); 
     } 
     }); 
    } 
    }); 
}); 
相關問題