I just started to get an idea of AJAX. For this i am trying out an example i found while searching on my local machine. But it is not working.
The page has some static text when page is loaded, once we scroll down, new dynamic text is added using ajax, but its not adding new text while scrolling.
The html file code is:
<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>
It calls getdata.pl. Code in getdata.pl is
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";
So this is not working. can you please help me in getting it working. Please let me know whats missing in it.
tag.
– kailash19 Jul 18 '12 at 13:44