2016-05-11 7 views
2

私は正しい方法でそれを解決する方法がわからない問題に直面しています。以下のコードを使用すると、実際にサーバーから文字列レスポンスが返されます。シリアライズ文字列形式として表示

私は何をしてレスポンスを配列にすることができ、データベースをループして更新できますか?

応答

string(114) "item[]=6&item[]=18&item[]=19&item[]=20&item[]=7&item[]=24&item[]=25&item[]=26&item[]=27&item[]=8&item[]=9&item[]=5" 

jQueryの

$('body.pages_page_x3soft-page-tree .subsubsub .button-primary').on('click', function(){ 
     items = $('body.pages_page_x3soft-page-tree ul.x3Soft-parent').sortable('serialize'); 
     $.post(ajaxurl, {'action': 'ajax_x3softPageTreeUpdateSortOrder', 'items': items}, function(data){ 
      alert(data); 
     }); 
     return false; 
}); 

$('body.pages_page_x3soft-page-tree ul.x3Soft-parent').sortable({ 
axis: "y", 
    containment: "parent", 
    forcePlaceholderSize: true, 
    items: " li", 
    placeholder: "sortable-placeholder", 
    revert: true, 
    scroll: false, 
    tolerance: 'pointer', 
    cursorAt: { left: 5 }, 
    cursor: 'move', 
    sort: function(e){ 
     $('body.pages_page_x3soft-page-tree .subsubsub .button-primary').removeAttr('disabled'); 
    }, 
}); 

PHP

add_action('wp_ajax_ajax_x3softPageTreeUpdateSortOrder', 'ajax_x3softPageTreeUpdateSortOrder'); 
add_action('wp_ajax_nopriv_ajax_x3softPageTreeUpdateSortOrder', 'ajax_x3softPageTreeUpdateSortOrder'); 
function ajax_x3softPageTreeUpdateSortOrder(){ 
    var_dump($_POST['items']); 
    die(); 
} 

HTML

<ul class="x3Soft-parent ui-sortable" id="item-0"> 
    <li id="item_6" class="ui-sortable-handle">Resources</li> 
    <li id="item_18" class="ui-sortable-handle">Newsroom</li> 
    <li id="item_19" class="ui-sortable-handle">Photo Gallery</li> 
    <li id="item_20" class="ui-sortable-handle">Video Gallery</li> 
    <li id="item_7" class="ui-sortable-handle">About Us</li> 
    <li id="item_8" class="ui-sortable-handle">Products</li> 
    <li id="item_9" class="ui-sortable-handle">Services</li> 
    <li id="item_5" class="ui-sortable-handle">Home</li> 
</ul> 

答えて

1

現在のPHPコードを以下のように置き換えてください。

function ajax_x3softPageTreeUpdateSortOrder(){ 
    $params = array(); 
    parse_str($_POST['items'], $params); 
    var_dump($params); 
    die(); 
} 
+0

素晴らしいです! –

関連する問題