我想知道为什么我的 jquery UI 没有创建一个我可以解析为 php 的数组,这是我的列表
<ul id="sortable">
<li id="firstname" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>firstname</li>
<li id="lastname" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>lastname</li>
<li id="title" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>title</li>
<li id="book_title" class="ui-state-default"><span class="ui-icon ui-icon-arrowthick-2-n-s"></span>book_title</li>
</ul>
这是jQuery
<script>
$(function() {
$( "#sortable" ).sortable({
placeholder: "ui-state-highlight",
opacity: 0.6,
update: function(event, ui) {
var info = $(this).sortable("serialize");
alert(info);
$.ajax({
type: "POST",
url: "home.php",
data: info,
context: document.body,
success: function(){
}
});
}
});
$( "#sortable" ).disableSelection();
});
</script>
这是 alert (info) 给出的结果
book[]=title
我希望能够将数组发布到 php,以便用户可以根据他在列表中的更改方式来更改输出的顺序。有人帮忙
从这里编辑,我的 home.php 文件
<?php
header("Content-type: text/xml");
include_once("config.php");
parse_str($_POST['data'], $order);
echo $order;
$query = "SELECT `author`.`surname`,`author`.`firstname`,`publication`.`title`,`book`.`book_title` FROM author, book, publication ";
$resultID = mysql_query($query, $conn) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
foreach($order as $col){
$xml_output = "\t\t<$col>" . $row[$col] . "</$col\n";
}
$xml_output .= "\t</entry>\n";
}
$xml_output .= "</entries>";
echo $xml_output;
?>