/ / Come inviare un modulo creato dinamicamente utilizzando JQuery? - javascript, jquery

Come inviare un modulo creato dinamicamente usando JQuery? - javascript, jquery

Invia non funziona da me, per favore qualcuno può risolvere questo?

$(function(){
$("#postImg").click(function() {

var form = $("<form/>", {
action: "checkout.php",
method: "POST"
});

form.on("submit");
$.each(["tprice", "tevents"], function(i, v) {
$("<input/>", {
type: "hidden",
name: v,
value: $("#" + v).text()
}).appendTo(form);
});
form.submit();
return false;
});
});

risposte:

4 per risposta № 1

Quello che stai facendo qui sta provando a fare una richiesta POST HTTP in modo davvero circolare (creando un modulo solo per lo scopo, popolandolo, pubblicandolo e quindi scartandolo).

Sarebbe molto più facile e meno confuso da usare direttamente jQuery.post anziché.

Per esempio:

var parameters = {
"tprice": $("#tprice").text(),
"tevents": $("#tevents").text()
};
$.post("checkout.php", parameters);

1 per risposta № 2

Perché stai tentando di pubblicare un modulo che non viene associato al DOM? Forse

$.post("checkout.php", { paramName: "value", paramName2: "value2" } );

è quello che ti serve?