【问题标题】:Get current Id order and post in php获取当前 ID 订单并在 php 中发布
【发布时间】:2019-03-14 00:19:02
【问题描述】:

我有一个 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 ?

【问题讨论】:

  • 使用 DOMDocument 解析 HTML,创建一个 ID 数组,然后发布它们。
  • 谢谢,我想我明白了,我试试这个

标签: php html list post


【解决方案1】:

您可以使用 javascript 获取 id 和 Ajax 调用以将其发布到 url。

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);

【讨论】:

    猜你喜欢
    • 2020-05-08
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2019-03-16
    • 2015-03-30
    • 1970-01-01
    • 2017-10-11
    相关资源
    最近更新 更多