How can i make this code wait till the form gets a response. the form must submit to recurly and receive a response from recurly before it can go on.
if there is a way to assure there is a response would be nice kinda like success: or error:
$("#pay_window").dialog({
autoOpen: false,
width: 600,
buttons: {
"Submit Payment": function(){
$("#PaymentForm").submit();
<--- NEED A WAIT FUNCTION HERE --->
var dialogbox = $(this);
$.ajax({
url: "/payment",
data: $(this).find([company_id, billing_email, first_name, last_name, recurly_token, selected_plan, account]).serialize(),
type: "POST",
success: function (data) {
dialogbox.dialog("close");
alert('Payment Completed')
},
error: function (jqXHR, textStatus, errorThrown) {
alert('error: ' + textStatus + ': ' + errorThrown);
}
});
return false;
}
}
});
completeoption of$.ajax