我刚刚开始了解 AJAX。为此,我正在尝试在本地计算机上搜索时找到的示例。但它不起作用。
页面加载时页面有一些静态文本,一旦我们向下滚动,使用 ajax 添加新的动态文本,但在滚动时不会添加新文本。
html文件代码为:
<script type="text/javascript" language="javascript">
$(document).ready(function () {
$(window).scroll(function () {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
sendData();
}
});
function sendData() {
$.ajax(
{
type: "POST",
url: "https://localhost/kailash/cgi/testing/getdata.pl",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: "true",
cache: "false",
success: function (msg) {
$("#myDiv").append(msg.d);
},
Error: function (x, e) {
alert("Some error");
}
});
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="myDiv">
<p>
Static data initially rendered.
</p>
它调用 getdata.pl。getdata.pl 中的代码是
our $resp;
my $cgi = new CGI;
print $cgi->header();
$resp = "<p>This content is dynamically appended to the existing content on scrolling.</p>";
return "$resp\n";
所以这是行不通的。你能帮我让它工作吗?请让我知道其中缺少什么。