Jquery kullanarak php kodu içeren sorun ferahlatıcı div

3 Cevap php

Bunu yapmak için nasıl SO 3 mesajlarını okumak, ama nedense çalışmıyor değil.

Sayfa index.php, ben bu komut dosyası var:

<script type="text/javascript">

function update() {
  $.get("index.php", function(data) {
    $("#uploadcount").html(data);
    window.setTimeout(update, 5000);
  });
}

</script>

ve daha sonra bu index.php de, div

<div id=uploadcount>
<?
$result = mysql_query("SELECT * FROM mydb");
$num_rows = mysql_num_rows($result);
echo "<h1>$num_rows</h1><h2>rows</h2>";
?>
</div>

The php is displaying the row count fine, but it wont refresh the number.
(i have latest jquery build included in head of index.php)

3 Cevap

inşaat büyük bir çözüm buldu

<script type="text/javascript">
$(document).ready(function() {
setInterval(function()
{
     $('#uploadcount').fadeOut("fast").load('uploadcount.php').fadeIn("slow");
}, 10000);

});
</script>


<div id="uploadcount">
<? include("uploadcount.php");?>
</div>

Tüm yardım için teşekkür ederiz.

Lütfen güncelleme fonksiyonu için bu kullanmayı deneyin

function update() {
	$("#uploadcount").load("index.php #uploadcount")
	window.setTimeout(update, 5000);
}

Çift tırnak içinde div kimliği kuşatan deneyin:

<div id="uploadcount">

Ayrıca, bir document.ready blok içinde jQuery koymak ve setTimeout çağrısı $ içinde olmamalıdır yöntemi olsun.:

<script type="text/javascript">
$(document).ready(function() {
    function update() {
      $.get("index.php", function(data) {
        $("#uploadcount").html(data);
      });
    }
    window.setTimeout(update, 5000);
});
</script>

Eğer seçici bir belgeden bir şey almak istiyorsanız, bir seçici ile, örneğin $.load kullanabilirsiniz:

$("#uploadcount").load("index.php #uploadcount");

http://docs.jquery.com/Ajax/load

Bu sadece yukarıda jQuery 1.2 ile çalışır.