Domanda

JS può inviare coppie nome / vale tramite document.testform.submit (); ? o deve essere inviato tramite i tag html, ad esempio

<INPUT TYPE="text" NAME="inputbox1" VALUE="This is such a great form!" SIZE=50><P>
È stato utile?

Soluzione

In genere si include un < input type = " nascosto " > nel modulo e imposta il valore desiderato nel gestore eventi prima che venga inviato.

<form method="post" action="thing" id="sandwich"><fieldset>
    <input type="text" name="inputbox1" value="This is such a great form!" />
    <input type="hidden" name="jsremark" />
</fieldset></form>

<script type="text/javascript">
    document.getElementById('sandwich').onsubmit= function() {
        this.elements.jsremark.value= 'Secretly it aint that great';
        return true;
    }
</script>

Altri suggerimenti

no, dovrai farlo da solo in JSON usando javascript

Con jquery è molto semplice:

$("#formid").bind("submit", function(){
 var str = $("#formid").serialize();
 $.post("url?"+str);
 return false;
}

È possibile impostare i dati di post di una richiesta Ajax utilizzando solo JS.

È semplicemente semplice usando jQuery:

$.post(url, {"name":"value"})
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top