So che questa domanda è vecchia, ma ecco come l'ho fatta su ASP.Net (C#) usando jQuery.
//Create the form in a jQuery object
$("<form action='/FormPostTo.aspx' method='post' target='nameofframe'></form>")
//Get the value from the asp textbox with the ID txtBox1 and POST it as b1
.append($("<input type='hidden' name='b1' />").attr('value',$('#<%= txtBox1.ClientID %>').val()))
//Get the value from the asp textbox with the ID txtBox2 and POST it as b2
.append($("<input type='hidden' name='b2' />").attr('value',$('#<%= txtBox2.ClientID %>').val()))
//Add the form to the body tag
.appendTo('body')
//Submit the form which posts the variables into the iframe
.submit()
//Remove the form from the DOM (so subsequent requests won't keep expanding the DOM)
.remove();
Solo una breve nota: ho fatto i tag input del genere piuttosto che concatenare, nel caso in cui il valore della casella di testo ha avuto una citazione ('
) in esso. Se l'hai concatenato, questo avrebbe rovinato l'HTML e non sarebbe stato analizzato correttamente.
Inoltre, questo rimuove il modulo dal DOM dopo che è stato utilizzato in modo da non riempire il DOM con elementi di modulo se si inviano ai più volte iFrame.
Un leggero cambiamento che si potrebbe fare, sarebbe quello di creare l'elemento del modulo, se non esiste e poi basta fare riferimento a essa per ID se già esiste e riutilizzarla.
fonte
2012-02-29 16:26:14
Non mi importa di Ajax. Tutto quello che voglio è di inviare un post a un iframe al di fuori di esso senza che l'utente debba fare clic su un pulsante di invio. Non posso passarli nell'iframe usando src perché non è parametri querystring che vuole. Il tag