serializeArray() Demo

This example uses serializeArray(), adds an extra name/value pair, displays the resulting array, and can POST the same data to the included helper endpoint.

Add Extra Data Top ↑

const formData =
    $( "#f1" ).serializeArray();

formData.push({
    name: "NewData",
    value: "Data value"
});

POST the Array Top ↑

$.post(
    "serialize-demo2ck.php",
    formData,
    function ( returnedData ) {
        $( "#display" ).text(
            JSON.stringify(
                returnedData,
                null,
                2
            )
        );
    },
    "json"
);

Backend PHP Top ↑

header(
    'Content-Type: application/json; charset=utf-8'
);

$response = [
    't1' => (string)($_POST['t1'] ?? ''),
    't2' => (string)($_POST['t2'] ?? ''),
    'NewData' =>
        (string)($_POST['NewData'] ?? '')
];

echo json_encode(
    $response,
    JSON_UNESCAPED_UNICODE
);

See jQuery POST.

Additional Original Learning Routes Top ↑

These original tutorial/demo routes are retained so no useful learner path is lost:






plus2net.com






We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer