php - Yii2 无法执行 Ajax
问题描述
我正在尝试在Yii中执行 Ajax 。但是给了我错误:
传递给 getElementById() 的空字符串
下面是我的 AJAX 代码:
$url1 = Yii::$app->homeUrl;
$crurl = 'https://'.$_SERVER['SERVER_NAME'].$url1;
$this->registerJs('$(document).ready(function(){
$(".glyphicon.glyphicon-eye-closed").click(function(){
$.ajax({
url: "'.$crurl.'?r=history/move",
type: "post",
data: {id: this.id},
success: function(data){
alert(data);
}
});
});
});
解决方案
检查以下选项;
检查
.glyphicon.glyphicon-eye-closed
具有 id attr 的类的 html 代码?替换
this.id
为$(this).attr('id')
;
推荐阅读
- java - 下载文件后如何返回视图
- c++ - 添加连接点不会生成 fire_* 方法
- regex - .htaccess 代码用于桌面 -> 移动 | 移动 -> 桌面?
- reactjs - 从返回函数内的 onChange 事件调度时出错
- asp.net - 为什么我的 Entity Framework Core Database-First 模型自定义更改在 Re-Scaffold 后消失了?任何解决方案
- c - 通过 ./configure --host=mingw32 后 Makefile 在制作时崩溃
- azure-log-analytics - LogMetric 不适用于微软扩展框架
- c++ - 用于添加 32 位元素数组的汇编函数无法正常工作
- lightningchart - IIFE版闪电图xydata
- android - Android 谷歌地图 moveCamera 无法正常工作