javascript - 将动态 javascript 变量传递给 PHP
问题描述
我想将一个 JavaScript 变量传递给 PHP,这是我的代码:
$('.info-button').on('click', function() {
var flag = $(this).data('flag');
if (flag) {
var index3 = $(this).parent().parent().parent().find('img').attr('src');
console.log(index3);
$('.inner').css("display", "block");
} else {
$('.inner').css("display", "none");
}
$(this).data('flag', !flag);
});
如何获取 index3,它是 PHP 的动态变量?
我试过:
<?php
echo "<script>document.writeln(index3);</script>";
?>
但我得到index3 没有定义
解决方案
推荐阅读
- python - 更改熊猫中的特定列
- php - 如何在 php exec 中使用 cgroups
- c - 如何使用 CFFI 在 C 中访问 Python dunder 方法?
- java - 无法推断基本网址。这在使用动态 servlet 注册或 API 位于 API Gateway swagger 2.10.5 后面时很常见
- flutter - 颤振:未处理的异常:无法加载资产:资产/语言/en
- swift - Vapor 4 - 创建一个列出所有可用路线的路线
- javascript - 等待 for 循环的完成
- signalr - Azure Function V2 dotnet signalr 和 cosmos 异常
- c# - 将 SQL 查询转换为 lambda 表达式
- flask - 当前用户的装饰者是管理员