How to call Flash class by Ikkez from JQuery script?

68 views
Skip to first unread message

Gosforth

unread,
May 25, 2023, 3:38:11 AM5/25/23
to Fat-Free Framework

I'd like to send ajax success result to PHP Flash class.
Is there any way to do this?
Regards

ved

unread,
May 25, 2023, 4:47:07 AM5/25/23
to Fat-Free Framework
Hello,

To put it plainly: you can't.

ikkez's Flash plugin (afaik) uses php sessions to show a flash message on your template on the next request. If that's what you want, you can just set the flash message on whichever script you're calling on your ajax request.

But If you want to show a flash message from an ajax call, I'm assuming you'll want to show the message immediately after the call is made and not only when the visitor reloads or changes the page.

And on that case, you should simply use javascript to show a flash message on the success/error callbacks of your ajax request.

Of the top of my head, an example for a very basic flash message in jQuery would look something like this:

$('body').prepend('<div class="someflashclass">Message here</div>');   // this will add the div with class "someflashclass" as the first element after the <body> tag.
setTimeout(() => { $('.someflashclass').remove() }, 3000);             // this will remove the flash div after 3 seconds

You can also surely find a few plugins that will offer flash message functionality if you prefer. Just search the web for something like "jquery flash message plugin"

Hope it helps.

Cheers

Gosforth

unread,
May 25, 2023, 4:29:56 PM5/25/23
to Fat-Free Framework
Thank you very much for great suggestion!
I was thinking about setting message and page redirection but this idea is good as well.
Anyway, I finally managed this with https://sweetalert2.github.io/ :-)
Reply all
Reply to author
Forward
0 new messages