<table id="SongList">
This is what I am using.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function() {
$("#sortable").sortable(
{opacity: 0.7,
revert: true,
scroll: true,
cursor: 'crosshair',
update : function () {
var order = $('#sortable').sortable('serialize');
//alert(order);
$("#info").load("Insert.asp?"+order);
//Refresh when we are done sorting, to get the new ordered list
$('#SongList').load('SongList.asp?DJID=1&chID=1');
}
});
});
</script>
<div id="info">Order your songs</div>
<table class="table table-bordered" id="SongList" style="width:420px; font-size:10pt; color:#CCC;">
<tr>
<th style="width:5%;">#</th>
<th style="width:15%;">Order</th>
<th style="width:100%;">Song Title</th>
<th style="width:20%;">Artist</th>
</tr>
<tbody class="row_position" id="sortable">
<tr id="favItem_49" class="dragit">
<td style="border-bottom:1px double #CCC;">0</td>
<td style="border-bottom:1px double #CCC;">49</td>
<td style="border-bottom:1px double #CCC;">Strutter</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_48" class="dragit">
<td style="border-bottom:1px double #CCC;">1</td>
<td style="border-bottom:1px double #CCC;">48</td>
<td style="border-bottom:1px double #CCC;">Do You Love Me</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_37" class="dragit">
<td style="border-bottom:1px double #CCC;">2</td>
<td style="border-bottom:1px double #CCC;">37</td>
<td style="border-bottom:1px double #CCC;">Who Wants to be Lonely</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_65" class="dragit">
<td style="border-bottom:1px double #CCC;">3</td>
<td style="border-bottom:1px double #CCC;">65</td>
<td style="border-bottom:1px double #CCC;">Tears are Falling</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_43" class="dragit">
<td style="border-bottom:1px double #CCC;">4</td>
<td style="border-bottom:1px double #CCC;">43</td>
<td style="border-bottom:1px double #CCC;">Love 'em and Leave 'em</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
</tbody>
</tr>
</table>
ASKER
Uncaught Error: cannot call methods on sortable prior to initialization; attempted to call method 'serialize'
<!DOCTYPE>
<html>
<head></head>
<body>
<div id="info">Order your songs</div>
<table class="table table-bordered" id="SongList" style="width:420px; font-size:10pt; color:#CCC;">
<tr>
<th style="width:5%;">#</th>
<th style="width:15%;">Order</th>
<th style="width:100%;">Song Title</th>
<th style="width:20%;">Artist</th>
</tr>
<tbody class="row_position" id="sortable">
<tr id="favItem_49" class="dragit">
<td style="border-bottom:1px double #CCC;">0</td>
<td style="border-bottom:1px double #CCC;">49</td>
<td style="border-bottom:1px double #CCC;">Strutter</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_48" class="dragit">
<td style="border-bottom:1px double #CCC;">1</td>
<td style="border-bottom:1px double #CCC;">48</td>
<td style="border-bottom:1px double #CCC;">Do You Love Me</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_37" class="dragit">
<td style="border-bottom:1px double #CCC;">2</td>
<td style="border-bottom:1px double #CCC;">37</td>
<td style="border-bottom:1px double #CCC;">Who Wants to be Lonely</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_65" class="dragit">
<td style="border-bottom:1px double #CCC;">3</td>
<td style="border-bottom:1px double #CCC;">65</td>
<td style="border-bottom:1px double #CCC;">Tears are Falling</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
<tr id="favItem_43" class="dragit">
<td style="border-bottom:1px double #CCC;">4</td>
<td style="border-bottom:1px double #CCC;">43</td>
<td style="border-bottom:1px double #CCC;">Love 'em and Leave 'em</td>
<td style="border-bottom:1px double #CCC;">KISS</td>
</tr>
</tbody>
</tr>
</table>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript">
const options = {
opacity: 0.7,
revert: true,
scroll: true,
cursor: 'crosshair',
update : function () {
var order = $('#sortable').sortable('serialize');
//alert(order);
$("#info").load("Insert.asp?"+order);
// Let's destroy it : https://api.jqueryui.com/sortable/#method-destroy
$("#sortable").sortable("destroy");
// Let's empty it so it doesn't look bad on user browser during the ajax refresh following
$("#SongList tbody").empty();
// or let's make it pro :)
// $("#SongList tbody").html("<tr><td><img src='/path/to/loading.gif'/></td></tr>");
//Refresh when we are done sorting, to get the new ordered list
$('#SongList').load('SongList.asp?DJID=1&chID=1').done(function() {
// Let's make it again
$("#sortable").sortable(options);
});
}
}
$("#sortable").sortable(options);
</script>
</body>
</html>
ASKER
ASKER
Make the UL sortable first before calling the serialize method.And I changed the time to 250 instead of 1000
// 250 is just enough for getting the order sent back to the page.
// Anything higher takes to long, and anything lower causes the order to get messed up.
setTimeout(function(){ $('#RowList').load('List.asp');}, 250);
ASKER
I get this error at the end of the first drag, which works, but then no other drag works due to this error.
Uncaught TypeError: $(...).load(...).done is not a function
--On this line
.done(function() {
$('#SongList').load('SongList.asp?DJID=1&chID=1').done(function() {
// Let's make it again
$("#sortable").sortable(options);
});
by :$('#SongList').load('SongList.asp', { DJID: 1, chID: 1 }, function() {
// Let's make it again
$("#sortable").sortable(options);
});
Active Server Pages (ASP) is Microsoft’s first server-side engine for dynamic web pages. ASP’s support of the Component Object Model (COM) enables it to access and use compiled libraries such as DLLs. It has been superseded by ASP.NET, but will be supported by Internet Information Services (IIS) through at least 2022.
TRUSTED BY
Open in new window