ToastNotification icon indicating copy to clipboard operation
ToastNotification copied to clipboard

Unable to show toast after ajax call completion.

Open AhmadHassanSahi opened this issue 4 years ago • 3 comments

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

                    }
                }

AhmadHassanSahi avatar Sep 30 '21 18:09 AhmadHassanSahi

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?

jsonarso avatar Dec 01 '21 20:12 jsonarso

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

RicardoMarinho avatar Jul 31 '22 17:07 RicardoMarinho

getResponseHeaders(jqXhr);

Yes, it did work after adding the getResponseHeaders call in error or success message.

tarangpandya avatar Sep 28 '22 15:09 tarangpandya