php - 如何使用ajax将javascript变量值传递给php变量以存储在codeighter的会话中
问题描述
我在 codeighther 工作,想将我的 javascript 变量值传递给 php,以便我可以将它存储在会话中,然后存储到数据库中。
以下是我到目前为止所尝试的。
<div id="wrapper">
<button id="detect-button">Detect Device</button>
</div>
<script>
$('#detect-button').ready(function() {
var detector = new MobileDetect(window.navigator.userAgent)
var test = document.write("Mobile: " + detector.mobile());
//document.write( "Phone: " + detector.phone());
//document.write( "Tablet: " + detector.tablet());
// document.write( "OS: " + detector.os());
// document.write( "userAgent: " + detector.userAgent());
});
$.ajax({
type: 'Post',
url: '<?php echo $base_url ?>Home/index',
data: ({
value: +detector.mobile()
}),
cache: false,
success: function(data) {
$('#results').html(data);
}
</script>
<p id="results"> </p>
解决方案
将检测器定义为全局变量。它目前的范围正在限制其使用
推荐阅读
- latex - 如何修复longtable LATEX的宽度
- arrays - 根据 ARRAY 元素对结果进行排序?
- python - 带有两个数据框的 Dask 折叠
- node.js - 关于使用 SSO Tile 保护关键云代工厂中的 vue js 前端应用程序和节点 js 后端应用程序
- discord.py - Discord.py 机器人重复命令
- python - 加速元胞自动机的绘图
- python - 解析Json响应值Python
- javascript - 将数据从 JSON 输出到模态
- javascript - 节点:`fast-sort` 包 - 排序不是函数
- javascript - 在Angular中使用Input传递数据时如何处理未定义?