POST data with JavaScript

Note (2025): This article dates back to 2009. The examples remain useful, though modern apps often prefer fetch()/XHR or form submissions driven by frameworks. The classic form‑build approach below still works universally. HTML 4.0 (W3C) defines how browsers submit forms: GET: append query string to the action URL (application/x-www-form-urlencoded). POST: send a request body to the action URL, using the content type indicated by enctype. Programmatic POST helper Add this in your page head: ...

July 7, 2009 · 1 min · Andrea Azzola

Submit di un Form tramite POST JavaScript

Secondo le specifiche HTML 4.0{:target="_blank" rel=“noopener”}: Se il metodo è GET, lo user agent prende il valore dell’azione, vi concatena un ? e il data set del form, mediante il content-type application/x-www-form-urlencoded. In questo caso i dati del form sono vincolati a codici ASCII. Se il metodo è POST, lo user agent effettua un submit HTTP POST utilizzando il valore dell’action e un messaggio creato in accordo con il content type specificato nell’attributo enctype. Vantaggi dei POST JavaScript Effettuare redirect diversi all’action Veicolare dati senza refresh della UI Evitare query string troppo lunghe e URL poco leggibili Esempio di submit POST Inserire il seguente codice nella sezione <head> della pagina HTML: ...

July 7, 2009 · 2 min · Andrea Azzola