yii2-notification-wrapper icon indicating copy to clipboard operation
yii2-notification-wrapper copied to clipboard

Pjax causes POST error

Open dartunian opened this issue 4 years ago • 6 comments

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

dartunian avatar Feb 09 '20 01:02 dartunian

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

loveorigami avatar Feb 09 '20 20:02 loveorigami

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

dartunian avatar Feb 11 '20 23:02 dartunian

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

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

loveorigami avatar Feb 12 '20 07:02 loveorigami

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.

dartunian avatar Feb 12 '20 19:02 dartunian

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...

loveorigami avatar Feb 12 '20 20:02 loveorigami

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

dartunian avatar Feb 14 '20 07:02 dartunian