Simple comet example using php and jquery

前端 未结 7 1357
一个人的身影
一个人的身影 2020-12-01 02:17

Can anyone give me a good and simple example of the comet technique using PHP?

I just need an example that uses a persistent HTTP connection or something similar. I

7条回答
  •  半阙折子戏
    2020-12-01 02:54

    You should use polling, or use a web server which is specially conceived for long requests and COMET, with a good JS backend:

    function listen() {
        $.get("/mylongrequestfile", {}, function(data) {
            $("#mydiv").html(data);
            listen(); // then launch again
        }));
    };
    

    Remember that COMET is "wait for data, if there's data return and exit", so JS backend will have to parse the data and re-launch the process of asking the server.

    In this example, if there is a server side problem or just a disconnection from the user side, the entire process will be broken (the function is only called if the request is successful)

提交回复
热议问题