我正在尝试通过jquery ajax在php代码中获取客户端视口的大小,但是出了点问题:
index.php
<body>
<script>
var h = $(window).height() - 83;
alert (h); // works
$.ajax({
type: "POST",
url: 'pass.php', // I also tried index.php directly
data: {h : h}
});
</script>
<?php
include ("pass.php");
$h = $_POST['h'];
echo $h; // doesn't work
?>
index.php中没有回声。
Index.php
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>
$(document).ready(function(){
var h = $(window).height() - 83;
//alert (h); // works
$.ajax({
type: "POST",
url: 'pass.php', // I also tried index.php directly
data: {h : h},
success:(function(data){
alert(data);
})
});
});
</script>
和pass.php
$h = $_POST['h'];
echo $h;
它给了我输出。:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句