Link to home
Start Free TrialLog in
Avatar of SevenAteAnthony
SevenAteAnthonyFlag for United States of America

asked on

Why Does ID Work for AJAX/jQuery POST? I Thought Only Names Attribs Worked For POST.

Hi Experts,

Thanks for reading. This question is simply to achieve an explanation of something I didn't know: why I can use id="menu_1" as a $_POST['menu'] array. Let me explain:

I am using jQuery Sortable and attempting to save placeholders of items when arranged. It's working great, however, I don't understand why $_POST['menu'] acquires the id of my element and places it into an array.

The HTML:

<li class="ui-state-default" id="menu_{$menu->menu_id}">
{$menu->name}
</li>

Open in new window


The JS:

$(document).ready(function(){
    $('#sortable').sortable({
        update: function()
        {
            serial = $('#sortable').sortable('serialize');
            $.ajax({
                url: "/dashboard/sort",
                type: "post",
                data: serial,
                error: function()
                {
                    alert("Oops! An error has occurred.");
                }
            });
        }
    });
});

Open in new window


The PHP at POST URL in JS:

$menu = $_POST['menu'];

Open in new window


Could this be the serialize call in the JS and data: serial? What does this mean?

Thank you!
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SevenAteAnthony

ASKER

Thank you!