我有一个ul列表
<ul id="new_fields">
<li id="id_1" class="ui-state-default">list 1</li>
<li id="id_7" class="ui-state-default">list 2</li>
<li id="id_4" class="ui-state-default">list 3</li>
</ul>
我想获取id的当前顺序并发布,例如,这将发布id_1,id_7和id_4。
php中是否有一种简单的方法来获取此oredr并发布到url?
答案 0 :(得分:0)
您可以使用javascript获取ID,并使用Ajax调用将其发布到网址。
lists = document.getElementsByClassName('ui-state-default');
x = []
for (var i=0, im=lists.length; im>i; i++) {
x[i] = lists[i].id;
}
// Here x will be ['id_1','id_7','id_4']
然后使用ajax将其发布到URL。
var url = "your_url_here.php";
var params = "array=" + x.toString();
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(params);