ajax, akış okuma aşamalı bir WordPress kullanmak?
this question okudum ama tam olarak benim sorumun cevabı değil.
Ne yazık ki, işlerim son Ajax baktı, artık mümkün doldurulan tamamlanmadan önce doğrudan responseText
erişim bu yana XHR nesne yer değiştirmiş gibi görünüyor.
AJAX kullanan bir sayfa yazmam gerekiyor (tercihen DV ama önerilere açığım) üzerinde hiçbir kontrolü var bir sunucudan HTTP üzerinden CSV veri almak için. Yanıt verileri oldukça büyük olabilir; metin megabayt nadir değildir.
Sunucu stream dostu. Hala iade ediliyor gibi doğrudan Javascript veri akışı, erişmek için herhangi bir yolu var mı?
Bir kaç tane daha var seçeneği yazılı bazı PHP kodu yaşayan orta ve kullandığı bir çeşit "Kuyruklu yıldız" tech (uzun yoklama, EventSource, vb), ama ben tercih ederim önlemek için bu mümkün.
İlgili olduğu durumda, kullanıcılar/Chrome/Opera ve eski tarayıcı uyumluluk sorunu değil Firefox'un son sürümü olan bu soru için varsayalım.
CEVAP
XMLHttpRequest.js Kullanın
https://github.com/ilinsky/xmlhttprequest
http://code.google.com/p/xmlhttprequest
- Teslim mütevazi standart-uyumlu (W3C) çapraz tarayıcı XMLHttpRequest 1.0 nesne uygulanması
- Düzeltmeler tuhaflıklar native XMLHttpRequest nesnesi kendi uygulamalarında gözlenen tarayıcılar
- Sağlar şeffaf XMLHttpRequest nesnesi aktivite günlüğü
PHP ile uzun yoklama kullanın:
output.php:
<?php
header('Content-type: application/octet-stream');
// Turn off output buffering
ini_set('output_buffering', 'off');
// Turn off PHP output compression
ini_set('zlib.output_compression', false);
// Implicitly flush the buffer(s)
ini_set('implicit_flush', true);
ob_implicit_flush(true);
// Clear, and turn off output buffering
while (ob_get_level() > 0) {
// Get the curent level
$level = ob_get_level();
// End the buffering
ob_end_clean();
// If the current level has not changed, abort
if (ob_get_level() == $level) break;
}
// Disable apache output buffering/compression
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', '1');
apache_setenv('dont-vary', '1');
}
// Count to 20, outputting each second
for ($i = 0;$i < 20; $i ) {
echo $i.str_repeat(' ', 2048).PHP_EOL;
flush();
sleep(1);
}
run.php:
<script src="http://code.jquery.com/jquery-1.6.4.js"></script>
<script src="https://raw.github.com/ilinsky/xmlhttprequest/master/XMLHttpRequest.js"></script>
<script>
$(function() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/longpoll/', true);
xhr.send(null);
var timer;
timer = window.setInterval(function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
window.clearTimeout(timer);
$('body').append('done <br />');
}
$('body').append('state: ' xhr.readyState '<br />');
console.log(xhr.responseText);
$('body').append('data: ' xhr.responseText '<br />');
}, 1000);
});
</script>
Bu çıktı:
state: 3
data: 0
state: 3
data: 0 1
state: 3
data: 0 1 2
state: 3
data: 0 1 2 3
state: 3
data: 0 1 2 3 4
...
...
...
state: 3
data: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
state: 3
data: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
state: 3
data: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
done
state: 4
data: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
IE için XDomainRequest içine bakmak gerekir
http://msdn.microsoft.com/en-us/library/cc288060(VS.85).aspx
parsererror bir WordPress kullanmak so...
&; Nasıl" backbone.js - Omurga bü...
ASP.NET Webforms ile AJAX kullanarak b...
Bir WordPress kullanmak başarı kontrol...
Dur bir WordPress kullanmak tüm aktif ...