How to trigger toaster after getting ajax response ?

MDB SupportCategory: MDB jQueryHow to trigger toaster after getting ajax response ?
imhim45 asked 2 weeks ago in MDB free, version:4.5.5

Hey there,

I wanted to trigger a toaster when user authentication gets success.

For example – If a user Clicks on Login button then AJAX will check credentials using PHP in back end and will give a response.

I want to trigger the toaster at that time.

Start your code here
$.ajax({
type:"POST",
url:'functions/action.login.php',
data:'email='+email+'&password='+password,
dataType:"text",
beforeSend:function(){
$("#submit").prop('value', 'Loading..');
},
success:function(data){
if(data!=0){
//I want toaster to trigger here when login is successful.
$(location).attr('href',data);
}
imhim45 replied 5 days ago

Got it. I’ll pass a url param and will trigger toaster on Dashboard.
But How do I do that ?
I don’t know how to trigger toaster other than onclick()

Anna Morawska replied 2 weeks ago

Hello,
so, after success ajax call you want to redirect the user to another URL and then trigger the toaster?
It’s quite tricky, redirecting will kill all scripts currently running in the browser. Maybe try to pass a parameter in the URL, and then depending on the passed parameter trigger a toaster on a new page.
Is this resolve your problem?
Best,
Ania

1 Answers
Anna Morawska answered 5 days ago

Hey,
you can trigger a toaster via jQuery :
toastr["info"]("I was launched via jQuery!")
You can check how it works on our docs page, just open the console and paste it in.
You can read more about that in our documentation.
Best,
Ania