阅读后"This question is actually about the correct syntax of how to send to the server a result from pagination() to showPagination() through Ajax."
,我会建议您以下内容:
Javascript:
// save current page to global variable
window.globalPageId = 0;
//the pseudo function
function showPagination(id) {
id || ( id = globalPageId );
var xhr = new xmlHttpRequest();
xhr.open("GET", "/yourPhpPage.php?pageId="+id, true);
xhr.send();
xhr.onreadystatechange = function() {
if(xhr.readyState == 4 && xhr.status == 200) {
globalPageId = xhr.responseText; //sure if the result is only id of page;
}
}
}
然后是 html:
<td><a href="javascript:showPagination(this.getAttribute('page-id')" page-id="id of page here, from php function">link text here</a></td>
或者 :
<td><a href="javascript:showPagination()">link text here</a></td>