$script = <<< JS
$("#delete-select").on("click", function(e){
e.preventDefault()
var keys = $("#w0").yiiGridView("getSelectedRows");
$.ajax({
url: "\yii\helpers\Url::toRoute(['delete-select']).",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
},
error : function(){
alert("Ошибка при отправке данных: перезагрузите страницу!");
}
})
});
JS;
$this->registerJs($script, yii\web\View::POS_READY);
Access to XMLHttpRequest at 'yiihelpersurl::toRoute(['delete-select'])' from origin 'site.ru' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https
Обращаю внимание, что он почему-то "\yii\helpers\Url::toRoute(['delete-select'])", выводит как "yiihelpersurl::toRoute(['delete-select'])."
$url = \yii\helpers\Url::toRoute(['delete-select']);
$script = <<< JS
$("#delete-select").on("click", function(e){
e.preventDefault()
var keys = $("#w0").yiiGridView("getSelectedRows");
$.ajax({
url: "$url",
type: "POST",
data: {id: keys},
success: function(){
alert("yes")
},
error : function(){
alert("Ошибка при отправке данных: перезагрузите страницу!");
}
})
});
JS;
$this->registerJs($script, yii\web\View::POS_READY);