请帮助解决我的问题。 是站点jQueryUI的示例 - http://jqueryui.com/sortable/#connect-lists
代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Sortable - Connect lists</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#sortable1, #sortable2 {
border: 1px solid #eee;
width: 142px;
min-height: 20px;
list-style-type: none;
margin: 0;
padding: 5px 0 0 0;
float: left;
margin-right: 10px;
}
#sortable1 li, #sortable2 li {
margin: 0 5px 5px 5px;
padding: 5px;
font-size: 1.2em;
width: 120px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable"
}).disableSelection();
} );
</script>
</head>
<body>
<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>
<ul id="sortable2" class="connectedSortable">
<li class="ui-state-highlight">Item 1</li>
<li class="ui-state-highlight">Item 2</li>
<li class="ui-state-highlight">Item 3</li>
<li class="ui-state-highlight">Item 4</li>
<li class="ui-state-highlight">Item 5</li>
</ul>
</body>
</html>
当您在sortable1和sortable2中添加元素时,我需要向服务器发送ajax post请求。怎么做?感谢。
答案 0 :(得分:0)
尝试使用sortable1,然后将其重复为sortable2。
var length1 = $("ul#sortable1 > li").length;
$("#sortable1").bind("DOMSubtreeModified", function() {
if ($("ul#sortable1 > li").length >= length1) {
$.ajax({
url: "some Url",
data: {parameter values},
success: function(data) {
},
dataType: "html",
type: "POST",
cache: false,
error: function() {
alert("Process Not Finished");
}
});
}
});
答案 1 :(得分:0)
您可以在sortable1和sortable2列表中更改序列进行ajax调用,如下所示。
$( "#sortable1, #sortable2" ).bind( "sortchange", function(event, ui) {
$.ajax({
url: "some Url",
data: {parameter values},
dataType: "json",
type: "POST",
success: function(data) {
}.
error: function() {
alert("Process Not Finished");
}
});
});