Ajax request after submit form

Hi,
trying to make a web request after a form was saved, but it looks like the form is being closed before the request was sent.

fd.spSaved(function (result) {
var postURL = “https://…my web service url…”;
var data = JSON.parse(’{“partnerID”:"’ + Dialog.getArgs().partnerID + ‘",“ticketID”:"’ + Dialog.getArgs().parentID + ‘",“title”:"’ + fd.field(“Title”).value + ‘",“author”:"’ + _spPageContextInfo.userDisplayName + ‘",“userId”:"’ + _spPageContextInfo.userId + ‘"}’);
jQuery.ajax({
url: postURL,
method: “POST”,
headers: {
“Accept”: “application/json”,
“Content-Type”: “application/json”
},
data: JSON.stringify(data),
success: function () {
console.log(“call successful.”);
}
});
});

Am I doing it the wrong way?

it seems to work with fd.spBeforeSave() instead of fd.spSaved() function.

Dear Alex,

Yes, spSaved() is not an async event, it’s executed and the form is closed.

It should run in spBeforeSave() just fine, and you can even utilize some async functionality in it, so it doesn’t complete saving until the request returns an answer.