Javascript 将成功添加到double jquery/ajax post

Javascript 将成功添加到double jquery/ajax post,javascript,jquery,ajax,jquery-mobile,Javascript,Jquery,Ajax,Jquery Mobile,我使用以下命令将表单数据从web应用程序发布到服务器端php和quickbase。php处理签名,将其附加到pdf中,并通过电子邮件发送结果 一切都很好,除了我没有这部分的真正成功功能: $('#sendbtn').click(function(){ signatures(); $.post( 'https://www.quickbase.com/db/dbname?act=API_AddRecord', $('form').serialize()); $.post

我使用以下命令将表单数据从web应用程序发布到服务器端php和quickbase。php处理签名,将其附加到pdf中,并通过电子邮件发送结果

一切都很好,除了我没有这部分的真正成功功能:

$('#sendbtn').click(function(){

    signatures();

    $.post( 'https://www.quickbase.com/db/dbname?act=API_AddRecord', $('form').serialize());

    $.post( 'fill.php', $('form').serialize(), $.mobile.changePage('#successpop', {transition: 'pop', role: 'dialog'}));

});
弹出窗口显示,但它不是任何成功的真正指标。在显示成功弹出窗口之前,我如何从其中一篇或两篇文章中获得回复?有条件地从一个帖子转到另一个帖子会很好,但我并不担心QuickBase帖子。在显示成功之前,我肯定需要确认fill.php帖子

我喜欢的是,它避免了重定向到我的应用程序之外的url

谢谢你的帮助

<form action="" encoding='multipart/form-data' encType='multipart/form-data'>
<input type=text name=_fid_6 >
<input type=text name=_fid_7 >
<input type=text name=_fid_8 >
<input type="hidden" name="img" id="img" />
<input type="button" value="Sign!" id="sendbtn" />
</form>  

        <script>
            $(document).ready(function() {
                $("#signature").jSignature()
            })
            function signatures(){
                var $sigdiv = $("#signature");
                var datax = $sigdiv.jSignature("getData","image");
                $('#img').val(datax);
                $sigdiv.jSignature("reset")
            }
        </script>

<script>
$(document).ready( function(){
    $('#sendbtn').click(function(){

        signatures();

        $.post( 'https://www.quickbase.com/db/dbname?act=API_AddRecord', $('form').serialize());

        $.post( 'fill.php', $('form').serialize(), $.mobile.changePage('#successpop', {transition: 'pop', role: 'dialog'}));

    });
});
</script>

<div data-role="page" id="successpop">
<div data-role="header" data-theme="c">
<h1>QAF Sent</h1>
</div>
<div data-role="content" data-theme="d">    
<h2>Your QAF has been sent</h2> 
<p><input type="button" data-inline="true" data-theme="b" value="Begin New QAF" data-icon="back" onclick="clearForm();"/></p>
</div></div>

$(文档).ready(函数(){
$(“#签名”).jSignature()
})
函数签名(){
var$sigdiv=$(“#签名”);
var datax=$sigdiv.jSignature(“getData”、“image”);
$('#img').val(datax);
$sigdiv.jSignature(“重置”)
}
$(文档).ready(函数(){
$('#sendbtn')。单击(函数(){
签名();
$.post($)https://www.quickbase.com/db/dbname?act=API_AddRecord“,$('form').serialize());
$.post('fill.php',$('form').serialize(),$.mobile.changePage('successpop',{transition:'pop',role:'dialog'}));
});
});
QAF发送
您的QAF已发送

这些$.post()中的一个将首先完成,另一个将完成。您不一定知道是哪一个设置了全局变量(如布尔值),该变量在第一个设置完成时设置为true,然后添加true检查。当成功函数看到值为true时,让它调用onDoubleSuccess()函数。像这样():


$(文档).ready(函数(){
$('#sendbtn')。单击(函数(){
var finishedFirstPost=false,
onDoubleSuccess=函数(){
//代码在这里
$.mobile.changePage('successpop',{transition:'pop',role:'dialog'});
};
签名();
美元邮政(
'https://www.quickbase.com/db/dbname?act=API_AddRecord',
$('form')。序列化(),
函数(){
如果(已完成的RSTPOST){
onDoubleSuccess();
}否则{
finishedFirstPost=true;
}
});
美元邮政(
'fill.php',
$('form')。序列化(),
函数(){
如果(已完成的RSTPOST){
onDoubleSuccess();
}否则{
finishedFirstPost=true;
}
});
});
});

此外,如果没有,您无法向外部域发送HTTP POST,因此您应该将Quickbase
$.POST()
更改为
$.get()
。这是一个证明这应该有效的例子。

太棒了!谢谢如果其中一个post失败,有没有办法显示一条简单的错误消息?如果您从$.post()切换到功能更强大的[$.ajax()]),则始终可以添加一个失败函数,谢谢。我尝试了$.ajax()——试图将第二篇文章嵌套在第一篇文章的success函数中,但没有成功。很高兴知道失败对$.post()不起作用。嗯,我实际上还没有得到工作的初步答案。只是无限期挂起。这是因为您正在将HTTP发布到外部域(因此它会引发一个失败事件),您想用$.get()替换到QuickBase的$.post()
<script>
  $(document).ready( function(){
    $('#sendbtn').click(function(){
      var finishedFirstPost = false,
      onDoubleSuccess = function() {
        //code goes here
        $.mobile.changePage('#successpop', {transition: 'pop', role: 'dialog'});
      };
      signatures();
      $.post(
        'https://www.quickbase.com/db/dbname?act=API_AddRecord',
        $('form').serialize(),
        function() {
          if(finishedFirstPost) {
            onDoubleSuccess();
          } else {
            finishedFirstPost = true;
          }
        });
      $.post(
        'fill.php',
        $('form').serialize(),
        function() {
          if(finishedFirstPost) {
            onDoubleSuccess();
          } else {
            finishedFirstPost = true;
          }
        });
    });
  });
</script>