I have the following javascript class and for some reason the current property is not being set to -1 when i'm done loading the records (or i'm not able to access the property correctly from an instance of the class). I'm new to javascript so any help would be appreciated.
var MyLib = function () {
this.current = 0;
MyLib.prototype.loadMore = function (id, loadingDivId, url) {
if (this.current > -1) {
this.current++;
$(loadingDivId).html("<h3>Loading more records please wait...</h3>");
$.get(url + this.current, function (data) {
if (data != '') {
$(id).append(data);
$(loadingDivId).empty();
} else {
this.current = -1; // seems like this isn't being set
$(loadingDivId).html("<h3><i>-- No more results -- </i></h3>");
}
});
}
}
};
Here's how i'm calling it
<script type="text/javascript">
$(function () {
var lib = new MyLib();
$('#loadMore').click(function () {
if (lib.current > -1) {
lib.loadMore("#results", "#loading", '/home/search/');
if (lib.current == -1) {
// Having problems getting into this portion
$("#loadMore").hide();
}
}
return false;
});
});
</script>