I’m using the following to post form data from a web app to both a server-side php and to quickbase. The fill.php processes the signature, appends it to a pdf, and emails the result.
Everything works fine, except I have no real success functions for this part:
$('#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'}));
});
The pop-up displays, but its not a true indicator of any success. How can I get a response back from one or both of these posts before displaying the success pop-up? It’d be great to conditionally go from one to the other post on success, but I’m not as worried about the QuickBase post. I definitely need to confirm the fill.php post before displaying success.
What I like about this is that it avoids a redirect to a url outside my app.
Thanks for any help!!
<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>
One of these $.post()s will complete first and one will complete second. You don’t necessarily know which so set a global variable (like a Boolean) that is set to true on the completion of the first and then add a check for true. When the success function that sees the value as true have it call a onDoubleSuccess() function. Like so (demo):
Also you can’t do an HTTP POST to an external domain without CORS support so you should change the Quickbase
$.post()to$.get(). Here is the API documentation showing that this shoudl work.