Quantcast
Viewing all articles
Browse latest Browse all 1024

Ajax onprogress dont work

@Esteban wrote:

Sorry for my bad English. I need help, this is my code. I have 2 files: 1.htm, 1.php

1.htm call 1.php in ajax:

1.htm:

<!DOCTYPE>
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<div id='cont1'></div>

<script type="text/javascript">
        var last_r_len = false;
        $.ajax('1.php', {
            xhrFields: {
                onprogress: function(e)
                {
                    var this_r, r = e.currentTarget.response;
                    if(last_r_len === false)
                    {
                        this_r = r;
                        last_r_len = r.length;
                    }
                    else
                    {
                        this_r = r.substring(last_r_len);
                        last_r_len = r.length;
                    }

                    $("#cont1").text(this_r);
                }
            }
        })
        .done(function(data)
        {
            console.log('Complete r = ' + data);
        })
        .fail(function(data)
        {
            console.log('Error: ', data);
        });


</script>


    </body>
</html>

1.php

<?php
$i=0;
while ($i <= 25) {
    echo $i++;
    flush();
    ob_flush();
    sleep(1);
}
?>

The program output every second "streaming" 1 2 3 ...etc. Is a test for a program more complex.
This code work in all browsers, chrome, firefox, etc. In ExeOutput i check "developer tools" in components, rendering engine for investigated this but i need help. Thank you

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 1024

Trending Articles