Why $ ('# sortthis'). Sortable ("serialize") just returns a string that says '[Object Object]'?

I am trying to get ajax sort version. I have this Javascript:

 
<script src="/Scripts/jquery-ui/jquery.ui.widget.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui/jquery.ui.mouse.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui/jquery.ui.sortable.js" type="text/javascript"></script>
<script type="text/javascript">
    // Sortable
    $(document).ready(function () {
        $("#sortThis").sortable({
            handle: '.handle',
            update: function () {

                // get new order
                var order = $('#sortthis').sortable('serialize');

                // excecute ajax for db update

                $.post(
                    "/find/ajaxactionhere",
                    order,
                    function (data) {
                        $("#info").html(data);
                    }
                );
            }
        });
    });
</script>

And this html in my asp.net mpc view:

<table>
    <thead>
        <tr>
            <th>headers</th>
            <th>headers</th>
        </tr>
    </thead>
    <tbody id="sortThis">
        <% foreach (var item in Model) %>
        <% { %>
            <tr id="list_<%: item.Tier %>">
                <td>
                <img class="handle" src="/sortIcon.gif" />
                </td>
                <td><%: item.data %></td>
</tr>
        <% } %>
    </tbody>
</table>

This allows me to reorder all the rows in the table. My action for processing an ajax send request is as follows:

    [HttpPost]
    public string ajaxactionhere(FormCollection form)
    {
        StringBuilder sb = new StringBuilder();

        sb.Append(":: ");

        if (form != null)
        {
            foreach (var key in form.AllKeys)
            {
                sb.Append(form[key]);
            }
        }
        else
        {
            sb.Append("null");
        }
        return sb.ToString();
    }

orderassigned to javascript variable $('#sortthis').sortable('serialize');. Whenever I show order, it says "[Object Object]". I cannot figure out how to get the contents of this object as a string.

Any help would be greatly appreciated.

+3
source share
1

sortThis T.

$('#sortthis').sortable('serialize') jQuery, , .

var order = $('#sortthis').sortable('serialize');

to

var order = $('#sortthis').sortable('serialize');

.

+2

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


All Articles