loveorigami / yii2-notification-wrapper

Yii2-notification-wrapper module renders a message from session flash (with ajax, pjax support and etc.) through Growl, Noty, Toastr and more libraries
MIT License
77 stars 20 forks source link

Pjax causes POST error #24

Open dartunian opened 4 years ago

dartunian commented 4 years ago

For some reason, whenever I load Pjax (or make ajax requests) on any page, POST requests get sent to /noty/default/index as well.

https://imgur.com/j0RQP2c

Not the greatest with JS, so a little bit confused what's going on here, any insight would be appreciated.

edit: to clarify, everything seems to work fine, i'm just unsure why these requests are being sent

loveorigami commented 4 years ago

Because every layer write message in flash

Yii::$app->session->setFlash('error',   'ajax error');

and after every ajax call notification-wrapper read this message from session once after POST request and display it in your layer (noty, toaster, etc..). Here https://github.com/loveorigami/yii2-notification-wrapper/blob/master/src/Wrapper.php#L170

If your dont send POST after ajax - you can see here https://github.com/loveorigami/yii2-notification-wrapper#disable-shownoty-after-ajax-calls

dartunian commented 4 years ago

I have been using this on all my pjax requests (and ajax), ie Pjax::begin(['id' => 'lib_js', 'clientOptions' => ['showNoty' => false]]); but still the problem persists https://i.imgur.com/axcF3hu.png

loveorigami commented 4 years ago

You have 500 error in noty/default/index (not found router?).

Please, check your config as in Readme, clear cache, etc...

dartunian commented 4 years ago

Okay, I did find that removing the 'template' option from my widget setup fixed the 500 error. Still unsure why this would be throwing 500 error.

'toast' => [
    'fade' => 'slow',
    'template' => '<div class="alert alert-%priority% alert-dismissible" role="alert">' .
                    '<button type="button" class="close" data-dismiss="alert">' .
                        '<span aria-hidden="true">&times;</span>' .
                        '<span class="sr-only">Close</span>' .
                    '</button>' .
                    '<span class="message"></span>' .
                '</div>',
],

Further, though, I don't understand why 2 requests to /noty/default/index are being sent per Pjax call.

loveorigami commented 4 years ago

May be you have grid view or submit form via ajax? Debug panel is enabled? If yes - disable it and see result in chrome console...

dartunian commented 4 years ago

Yes, I do use gridview, still unsure why the template option would be affecting routing. I'm not sure what you're suggesting, sorry.