如果mysql代码在index.php文件中,它工作正常,但无法刷新我试图将其移动到另一个文件,然后使用JQuery函数加载它.load(),
$("#pagesn").load("data.php");
现在它可以刷新,但链接不再工作任何想法?
Mysql代码:
<?php
require_once 'libs/db.class.php';
require_once 'libs/global.inc.php';
$sql1="select * from zinutes LIMIT 3";
$result1=$db->select($sql1);
$query="select count(*) as tot from zinutes";
$countset=$db->runquery($query);
$count=$db->get_row($countset);
$tot=$count['tot'];
$page=1;
$ipp=3;//items per page
$totalpages=ceil($tot/$ipp);
echo"<ul class='pages'>";
for($i=1;$i<=$totalpages; $i++)
{
echo"<li class='$i'>$i</li>";
}
echo"</ul>";
?>
点击链接的JS代码:
$(document).ready(function(){
function showLoader1(){
$('.search-background1').fadeIn(200);
}
function hideLoader1(){
$('.search-background1').fadeOut(200);
alert("yra");
}
$("#pagesn").on("click",".pages li",function(){
showLoader1();
$("#pagesn .pages li").css({'background-color' : ''});
$(this).css({'background-color' : '#A5CDFA'});
$("#resn").load("data1.php?page=" + $(this).attr("class"), hideLoader1);
});
});
尝试将php文件包含到特定的div中,然后用JS刷新它,得到相同的结果,而不是工作结果。
答案 0 :(得分:1)
尝试使用.ajax()函数
$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
这是一个使用XMLHTTPRequest的更广泛的示例,我正在使用here
// generate section content depending on request type
var requesttype = getUrlVars()["requesttype"];
if (requesttype == undefined) {
mainmenu();
document.getElementById("results").innerHTML = "<table border='0' cellspacing='0' cellpadding='0'><tr><td style='border-right:1px solid #E2E2E2'>" + mainmenuContent + "</td></tr></table>";
}
// mainmenu
function mainmenu() {
document.title = "Upgrade World > Home";
document.getElementById("breadcrumb").innerHTML = "<span style='color:#000;'>Home</span>";
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
}
xmlhttp.open("GET", "proxy.php?requesttype=ModelManufacturers&requestlanguage=" + requestlanguage, false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var a = xmlDoc.getElementsByTagName("modelmanufacturer");
prefix = "<table border='0' cellspacing='0' cellpadding='5'>"
mainmenuContent = "";
suffix = "</table>"
for (i = 0; i < a.length; i++) {
mainmenuContent = mainmenuContent + "<tr><td><a href='index.html?requesttype=ModelTypes&requestlanguage=" + requestlanguage + "&modelmanufacturer=" + encodeURIComponent(a[i].childNodes[0].data) + "'>" + a[i].childNodes[0].data + "</a></td></tr>";
}
mainmenuContent = prefix + mainmenuContent + suffix;
}