【问题标题】:Reordering XML Elements with jquery, then save XML file with php使用 jquery 重新排序 XML 元素,然后使用 php 保存 XML 文件
【发布时间】:2010-10-28 15:42:26
【问题描述】:

如何使用 jQuery 和 PHP 之类的东西对 xml 文件中的元素重新排序?

下面的 jQuery 插件允许交换 html 表格行或列表项,但我不知道如何通过单击按钮将这些更改保存回 XML 文件。

www.isocra.com/2008/02/table-drag-and-drop-jquery-plugin/

www.jqueryui.com/demos/sortable/

这里描述了一个重新排列/重新排序元素的函数: http://quest4knowledge.wordpress.com/2010/09/04/php-xml-create-add-edit-modify-using-dom-simplexml-xpath/

但这仅显示如何交换两个元素的位置,而不是多个元素。 可以将它们组合起来重新排序更长的元素列表吗?

我试图避免使用 mySQL,只使用 php/jquery/xml...

<?xml version="1.0" encoding="utf-8"?>
<gallery>
  <picture id="0001">
    <title>Title One</title>
    <description>Some text here</description>
  </picture>
  <picture id="0002">
    <title>Title Two</title>
    <description>Some more text here</description>
  </picture>
  <picture id="0003">
    <title>Title Three</title>
    <description>Some other text here</description>
  </picture>
</gallery>

谢谢安迪。

【问题讨论】:

    标签: php jquery xml


    【解决方案1】:

    JS提交重新排序的表数据:

    使用:jquery.json-2.2.js

    $(document).ready(function() {
        $('#table-1').tableDnD();
    });
    function sendData() {
        data = $('#table-1').tableDnDSerialize();
        document.dataform.data.value = $.toJSON(data);
        return true;
    }
    

    然后在PHP中接收数据:

    $data = json_decode(stripslashes($_POST['data']), true);
    $data = rawurldecode($data);
    $data = explode("&table-1[]=", $data);
    

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 2013-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多