【发布时间】:2019-01-26 06:30:28
【问题描述】:
我在 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>
【问题讨论】:
-
究竟是什么对您不起作用?应该发生什么?
-
实际上我想获取我存储在测试中的值并希望存储在 php 变量中以便我可以将其存储到数据库中
-
你能把PHP代码也贴出来吗?
-
我无法在 php 中获取值
-
php 代码只是一个带有 id 结果的 div