Skip to main content
PHP HTML Editor

Save with Ajax

Saves the document without reloading the page: the form is posted with fetch() and the server answers with JSON.

The PHP for this demo

// server
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    echo json_encode(['saved' => strlen($editor->posted())]);
    exit;
}
// browser
fetch(location.href, { method: 'POST', body: new FormData(form) });