I am storing the current page with a global variable. In the last page link, click Method to call a function to automatically modify the number of pages to the last page, and then invoke the method that contains the comment.
But I found that click on the "last page" the first time the system did not respond, and then click once to grab the last page of information!
To say that the global variable has not changed, it should be changed, as if the number of pages and the method of loading comments failed.
The code is as follows:
Copy Code code as follows:
var page = 1; Initialize pages as first page
var str = "";
$ (document). Ready (function () {
Lostguest (); How to load comments
$ ("A#first"). Click (function () {
page = 1;
Lostguest ();
});
$ ("A#last"). Click (function () {
if (page > 1) {
--page;
Lostguest ();
}
else {
page = 1;
Alert ("It's already the first page!") ")
}
})
$ ("A#next"). Click (function () {
if (Page < PageCount) {
++page;
Lostguest ();
}
else {
Alert ("It's already the last page!") ");
}
})
$ ("A#all"). Click (function () {
Getpagecount ();
Lostguest ();
});
})
var getpagecount = function () {
var type = "Getpagecount";
$.ajax ({
URL: ' getcount.ashx?type= ' + type,
Type: "Get",
DataType: ' Text ',
Beforesend:function () {
},
Error:function () {
Alert (' Get the number of system log records failed ');
},
Success:function (count) {
Pages = number (count);
}
})
}
var lostguest = function () {
$.ajax ({
URL: ' sqlhelper.ashx?page= ' + page,
Type: "Get",
DataType: ' JSON ',
Beforesend:function () {
$ ("#loading"). Show ();
},
Error:function () {
Alert (' Get system log failed ');
},
Success:function (msg) {
$ ("#guest"). empty ();
if (msg!= "0") {
var data = Msg.log;
str = "";
$.each (data, function (I, n) {
STR + + "<p id= ' Xuhao ' > Serial number:" + N. Serial number + "Publication date" + N. Date + "Username:" + N. operator + "</p>";
STR + + "<p id= ' content ' > Contents:" + N. Event + "</p>";
});
$ ("#guest"). Append (str);
$ ("#loading"). Hide ();
}
else {
Alert ("0");
}
}
})
}
I don't know what's going on. Can you explain??
PS: Later found an alternative method to achieve this effect. The code is as follows:
Copy Code code as follows:
var page = 1;
var str = "";
var PageCount; Storage Total Pages
$ (document). Ready (function () {
Getpagecount (); How to get the total number of pages
Lostguest ();
$ ("A#first"). Click (function () {
page = 1;
Lostguest ();
});
$ ("A#last"). Click (function () {
if (page > 1) {
--page;
Lostguest ();
}
else {
page = 1;
Alert ("It's already the first page!") ")
}
})
$ ("A#next"). Click (function () {
if (Page < PageCount) {
++page;
Lostguest ();
}
else {
Alert ("It's already the last page!") ");
}
})
$ ("A#all"). Click (function () {
page = PageCount; Update current pages to total pages
Lostguest ();
});
})
var getpagecount = function () {
var type = "Getpagecount";
$.ajax ({
URL: ' getcount.ashx?type= ' + type,
Type: "Get",
DataType: ' Text ',
Beforesend:function () {
},
Error:function () {
Alert (' Get the number of system log records failed ');
},
Success:function (count) {
PageCount = number (count); Read Total pages
}
})
}
var lostguest = function () {
$.ajax ({
URL: ' sqlhelper.ashx?page= ' + page,
Type: "Get",
DataType: ' JSON ',
Beforesend:function () {
$ ("#loading"). Show ();
},
Error:function () {
Alert (' Get system log failed ');
},
Success:function (msg) {
$ ("#guest"). empty ();
if (msg!= "0") {
var data = Msg.log;
str = "";
$.each (data, function (I, n) {
STR + + "<p id= ' Xuhao ' > Serial number:" + N. Serial number + "Publication date" + N. Date + "Username:" + N. operator + "</p>";
STR + + "<p id= ' content ' > Contents:" + N. Event + "</p>";
});
$ ("#guest"). Append (str);
$ ("#loading"). Hide ();
}
else {
Alert ("0");
}
}
})
}
The first code problem can you explain?? Thank you!