gpt4 book ai didi

javascript - 将成功添加到双 jquery/ajax post

转载 作者:行者123 更新时间:2023-11-29 15:44:26 24 4
gpt4 key购买 nike

我正在使用以下内容将表单数据从网络应用程序发布到服务器端 php 和 quickbase。 fill.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>

最佳答案

其中一个 $.post() 将首先完成,一个将在第二个完成。您不一定知道哪个,因此设置一个全局变量(如 bool 值)在第一个完成时设置为 true,然后添加一个 true 的检查。当将值视为 true 的成功函数调用 onDoubleSuccess() 函数时。像这样 ( demo ):

<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>

此外,如果没有 CORS support,您将无法对外部域执行 HTTP POST。所以您应该将 Quickbase $.post() 更改为 $.get()。这是 API documentation表明这应该有效。

关于javascript - 将成功添加到双 jquery/ajax post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13958455/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com