When I use this code, I get this error as the answer:
Bad request (# 400): cannot verify your details
$(document).on('click', '[data-toggle-active-menu-items]', function(e){ e.preventDefault(); var id = $(this).data('toggle-active-menu-items'); $.ajax({ url: 'active', type: 'POST', data: {'id': id, _csrf: yii.getCsrfToken()}, contentType: "application/json; charset=utf-8", dataType: "json", success: function(data) { if (data.active == 1) { $('#list-' + id + ' [data-toggle-active-menu-items]').html('<span class="glyphicon glyphicon-eye-open"></span>'); } else { $('#list-' + id + ' [data-toggle-active-menu-items]').html('<span class="glyphicon glyphicon-eye-close"></span>'); } } }); });
I tried adding
_csrf: yii.getCsrfToken ()
and
contentType: "application / json; charset = utf-8",
dataType: "json",
but it does not work
it works when I add this to my controller, but it is not good, I do not want to disable csrf check
public $ enableCsrfValidation = false;
How can i fix this?
source share