2

I was reading a lot of things about comet programming but I'm thinking if this implementation could be possible.

this is my jscript

$.ajax({
   url:"mypage.php",
   onProgress:{function(rsp){ //i know there is no such function like this
     $("#mydiv").append(rsp+"<br>");
   }}
});

and this is my mypage.php

<?php
    while(true){
    ob_start();
      echo time();
    ob_flush();
    }
    ?>

now what i want is my ajax request would fetch results during progress. Is this possible?

1

2 Answers 2

1

for this thing to happen you have to use comet technique.... please refer

What is the best way of showing progress on an Ajax call?

Sign up to request clarification or add additional context in comments.

Comments

1

Heres the polling way todo it, if your only looking to grab the time. why have an infinite loop using resources.

<?php
//polling.php
if(isset($_GET['poll']) && $_GET['poll']=='1'){
$out = array('thetime'=>date("F j, Y, g:i:s a")); 
echo json_encode($out);
die;
}
?>


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
function poll(){
   setTimeout(function(){

      $.ajax({ url: "http://localhost/polling.php?poll=1",cache: false,
      success: function(data){
      //Do something with returned json
      $("#time").replaceWith("<p id=\"time\">The Server Time & Date is: "+ data.thetime +"</p>");
        //Next poll
        poll();
      }, dataType: "json"});
     // 1/2 a sec
  }, 500);
}

$(document).ready(function(){
    poll();
});
</script>

<p id="time">The Server Time & Date is: <?php echo date("F j, Y, g:i:s a");?></p>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.