How to trigger toaster after getting ajax response ?

imhim45 asked 3 months ago

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

Anna Morawska commented 2 months 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


imhim45 commented 2 months 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()


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


Please insert min. 20 characters.
Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: jQuery
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No