index.php
<script>
var h = $(window).height();
alert (h); // works fine - shows 580
$.ajax({
type: "POST",
url: 'index.php',
data: {h : h},
success:(function(data){
console.log( data );
})
});
</script>
结果控制台显示了整个index.php文件,而不是h
数据(580)!?
最佳答案
您在 console.log( data );
行中使用的数据是data
您在 success:(function(data){
行中声明这是您通过请求 index.php
获得的 HTTP 响应的正文.
它与您在 data: {h : h},
行中使用的数据属性无关或变量h
.
关于php - 控制台日志显示整个文件而不是数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24841070/