我想用两种不同的方式发送一个html表单
首先,我需要一个jQuery .submit()将信息发送到and服务,然后直接将表单发送到我的数据库。
现在我的问题是,当我使用event.preventDefault()时,它总是只将信息发送到when服务,而不是数据库。
如果我不使用pereventDefault();它会将信息发送给the服务,但在竞争条件下,它不会等待成功函数post.done()。信息转到数据库,而不是我的not服务。
jQuery('#sendform').submit(function(event) {
event.preventDefault(); //here comes the problem
var post = jQuery.post(url, {
email: email,
firstname: vorname,
surname: nachname,
origin: origin,
newsletter: newsletter
});
post.done(function(data) {
console.log("webservice-done")
//at this point the data should be send to databdase via send.php
});
});这是我的HTML表单:
<section class="formular" id="formular">
<form id="sendform" action="send.php" method="post" enctype="multipart/form-data">
<div class="links">
<input id="idvorname" name="vorname" type="text" placeholder="Vorname*" required/>
<br>
<input id="idnachname" name="nachname" type="text" placeholder="Nachname*" required/>
<br>
<input id="idemail" name="email" type="text" placeholder="E-Mail-Adresse*" required/>
<p>* Pflichtfeld</p>
</div>
<div class="absenden">
<input id="senden" type="submit"/></input>
</div>
</form>因此,如果我使用preventDefault(),jQuery部分中的post就完成了,数据被发送到but服务,而不是通过send.php发送到数据库。如果我不使用preventDefault(),数据就不会正确地发送到我的via服务,而是通过send.php发送到我的数据库。
有没有可能让它像preventDefault()那样发送到any服务。只有在这个完成之后,它才会发送到数据库?
我已经尝试过使用jQuery表单插件,但它也不起作用。和以前一样的错误。我还尝试在post.done函数中使用.submit(),但最终只是陷入了一个向but服务发送无限数据的循环。
任何真正有用的帮助
https://stackoverflow.com/questions/38480366
复制相似问题