问题
I want to send a form and control what happens after with jQuery. I cannot use php. My server have cgi to process the data. How to send the form to the cgi using jQuery?. I don't know how to do it but I tried things like this:
$(function(){
var name = $("input:text").val("name"); ;
$(":submit").click(function(e){
e.preventDefault();
load("http://cgi.myDomain.com/FormMail.pl", ( name ));
});
})
The html:
<Form id="formulari" method="POST" action="http://cgi.aDomain/FormMail.pl"> <p> <input type="hidden" name="recipient" value="anE-mail"> <input type="hidden" name="subject" value="Form send"> <input type="hidden" name="redirect" value="http://www.theSamePage.html"> </p> <form> <input type="text" name="name" value="name"/> <input type="submit" value="Send"/> </form> </div> <div class="answer">Thank you</div>
回答1:
You should use AJAX, with it you can submit your form using POST or GET method and you receive an answer from your server. Also, it allows you to make things happen without reload your page.
here is a cool tuturial
Ajax tuturial
EDIT
try this, please note that I'm just using this piece of html, no form, just the input elements
html
<input type="text" id="name" name="name" value="name"/>
<input class="send" type="submit" value="Send"/>
JQuery
$('.send').on('click', function(event) {
$.ajax({
type: "POST",
url: "http://cgi.aDomain.com/FormMail.pl",
data: {name: $("#name").val()},
error: function(result) {
var data_received = $(result).find("h1");
alert(data_received );
},
success: function(result) {
alert(result);
}
});
});
来源:https://stackoverflow.com/questions/12246153/send-form-to-cgi-with-jquery