yii2-notification-wrapper
yii2-notification-wrapper copied to clipboard
Pjax causes POST error
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
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
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
You have 500 error in noty/default/index (not found router?).
Please, check your config as in Readme, clear cache, etc...
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">×</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.
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...
Yes, I do use gridview, still unsure why the template option would be affecting routing. I'm not sure what you're suggesting, sorry.