• item1
  • Jquery sortable serialize returns empty string

    HTML:

    <ul id="categories_list" class="ui-sortable"> <li class="cat_row" style=""> item1 </li> <li class="cat_row" style=""> item2 </li> <li class="cat_row"> item3 </li> </ul> 

    JavaScript:

     $("#categories_list").sortable({ placeholder: 'sortable_placeholder', update : function () { var order = $("#categories_list").sortable('serialize'); console.log(order); } }); 

    order returns an "empty string", why is this?

    +6
    source share
    2 answers

    The id ids on your li should look like this:

     <ul id="categories_list" class="ui-sortable"> <li class="catRow_1" style=""> item1 </li> <li class="catRow_2" style=""> item2 </li> <li class="catRow_3"> item3 </li> </ul> 

    You need the order number to be separated by an underscore in accordance with here .

    +15
    source

    Serializes the sortable id element in a form representing the form / ajax. Calling this method creates a hash that can be added to any URL to easily send a new order to the server.

    You need to specify an identifier for LI tags!

    See http://jsfiddle.net/m47mq/

    +6
    source

    Source: https://habr.com/ru/post/912650/


    All Articles