[jQuery] Jquery Ajax does not support HTTP Streaming ?
Hi everyone,
I want a solution to keep a connection open with my client so he can
get almost a live update and also we don't want Ajax to connect every
few minutes (we are building almost real-time web game)
I came a cross this nice article http://ajaxpatterns.org/HTTP_Streaming
which tell you some solution to do this.
I did it in my script and it's working fine if I access the script
directly (from browser) but when I try to do it with JQuery Ajax, it
will wait until the script close the connection then i will do the
action.
to explain more, here is my 2 scripts:
==============================================
index.html:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$.ajax({
type: "GET",
url: "/status.php",
dataType: "script",
async: true
})
}
==============================================
status.php
<?php
if (ob_get_level() == 0) ob_start();
hardFlush();
echo "SysMsg('Welcome 1');";
ob_flush();flush();
sleep(5);
echo "SysMsg('Welcome 1');";
ob_flush();flush();
sleep(5);
ob_end_flush();
function hardFlush(){
// Like said in PHP description above, some version of IE (7.0 for
example)
// will not 'update' the page if less then 256 bytes are received
// Send 250 characters extra
echo ' ';
echo ' ';
echo ' ';
echo ' ';
echo ' ';
flush();
ob_flush();
}
?>
================================
Anyone know if it's possible using Jquery and Ajax ?
Thanks