Unable to show toast after ajax call completion.
I want to show my toast when ajax calls return after completion. I tried to do it in Controller Action Method but it does not work
function GetOneDriveFileDownloadURL() {
$("body").addClass("loading");
$.ajax({
type: "GET",
url: "/Ajax/GetOneDriveFileDownloadURL",
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function (xhr, status, error) {
}
}).done(function (data) {
var link = document.createElement('a');
link.href = data;
link.download = "Test.txt";
link.dispatchEvent(new MouseEvent('click'));
$("body").removeClass("loading");
});
}
> API Success Call
``
if (OneDriveApi.AccessToken.AccessToken != null)
{
if (fileOneDriveItem != null)
{
_notifyService.Success("This is a Success Toast",100000);
return new JsonResult(fileOneDriveItem.DownloadUrlAnnotation);
}
}
Facing the same issue. Notifications will pop up on page refresh or redirect but not on the actual response of the ajax call.
Related open issues: #8 and #2
Any updates on this?
Hi community,
After some research, I finally found the solution for this issue. In order to trigger the notification you must have this inside of your ajax call:
error: function(jqXhr) { getResponseHeaders(jqXhr); }
Hope this helps you! 😎 Best Regards
getResponseHeaders(jqXhr);
Yes, it did work after adding the getResponseHeaders call in error or success message.