首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送html表单2次,互不阻塞

发送html表单2次,互不阻塞
EN

Stack Overflow用户
提问于 2016-07-20 19:42:59
回答 0查看 41关注 0票数 0

我想用两种不同的方式发送一个html表单

首先,我需要一个jQuery .submit()将信息发送到and服务,然后直接将表单发送到我的数据库。

现在我的问题是,当我使用event.preventDefault()时,它总是只将信息发送到when服务,而不是数据库。

如果我不使用pereventDefault();它会将信息发送给the服务,但在竞争条件下,它不会等待成功函数post.done()。信息转到数据库,而不是我的not服务。

代码语言:javascript
复制
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表单:

代码语言:javascript
复制
<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服务发送无限数据的循环。

任何真正有用的帮助

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38480366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档