我使用 ajax 重新加载页面,但我有一个问题,即 javascript 代码仅在第一次工作,然后在刷新后它不起作用,我将此 javascript 代码用于 ajax:
function showUser(str, pageno, type, sub) {
if (str == "" || pageno == "" || type == "" || sub == "") {
document.getElementById("txtHint").innerHTML = "";
return;
}
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "<?php echo $view['router']->generate('listing') ?>?page=" + pageno + "&genre=" + str + "&cat=" + type + "&subcat=" + sub, true);
xmlhttp.send();
}
在列表页面中我喜欢这样:
$(document).ready(function () {
alert('test'); //I see alert message only at the first time I run the page
$("#category-table").tablesorter();
});
有人有想法吗?