2012-07-06 123 views
0

如果MySQL代码是在index.php文件中,它工作正常,但它不能被刷新我试图将其移动到另一个文件,然后加载它与JQuery函数.load( ),页面不工作后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

请问,如果你加载一个静态页面它工作(意思是什么像data.html data.html不需要服务器端代码)? – 2012-07-06 10:50:53

+0

试试'$(document).on(“click”,“pages li”,function(){...})'看看会发生什么? – 2012-07-06 10:54:08

+0

与html页面工作正常,与$(文档)不起作用。 – 2012-07-06 10:58:31

回答

1

尝试使用阿贾克斯()函数

$.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; 
}