English 中文(简体)
j/ 查询支持 转让- 编码: chunked
原标题:jQuery support Transfer-Encoding:chunked

i m a web developer. in my script use header() to set "Transfer-Encoding:chunked". and flush() to webpage. it will print in webpage time-shared. it works ok. but, when i use jQuery.ajax() to request this.it always output all together(chunked unuseful).

如何溶解这个? 使用 jQuery ajax 中的块状编码?

问题回答

you cannot use jquery.ajax to read chunked http response continuously. jquery ajax will call the success callback function only when connection terminates. You should use this jquery plugin.

如果您正在使用php, 您可以使用此代码 :

 <html>
        <head>
            <script src="jquery-1.4.4.js"></script>
            <script src="jquery.stream-1.2.js"></script>
            <script>

                var println = function(string){
                    $("#console").append(string+"<br />");
                }

                $(document).ready(function(){



                    $.stream("数据串. php",{
                        open:function(){
                            println("opened");
                        },
                        message:function(event){
                            println(event.data);
                        },
                        error:function(){
                            println("error");
                        },
                        close:function(){
                            println("closed");
                        }
                    });



                });
            </script>
        </head>
        <body>


            <div id="console"></div>

        </body>
    </html>

在服务器侧面 :

数据串. php

<?php


   header( Content-Encoding ,  chunked );
   header( Transfer-Encoding ,  chunked );
   header( Content-Type ,  text/html );
   header( Connection ,  keep-alive );

   ob_flush();
   flush();

   echo("23123454645645646;");


   $p = "";
   for ($i=0; $i < 1024; $i++) { 
       $p .= " ";
   };
   echo($p.";");



   for ($i = 0; $i < 10000; $i++) {
      echo( 6;string; );
      ob_flush();
      flush();
      sleep(2);
   }




?>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签