duanpin9531 2014-06-11 12:27
浏览 47

Jquery PHP ajax在发送时显示服务器响应

I'd like to know if there is a possibility to show server response as it send it in real time in a long time consuming request.

Context:

1) A Jquery function send an ajax request to the server and open a Dialog widget waiting for response to update Dialogs content.

2) The PHP server process the request in a long time consuming process, 20s, or much more up to minutes, it's an intranet website the user knows thongs takes time, lots of stuff to manage.

While the server is working, I have several "echo" in my PHP code with some stuff to say and the server is still working on other things to "echo" more.

My problem is that the Dialog don't updates as long as the server has not finished.

I want to show the partial response in live as soon as the browser receives it, with a SINGLE Ajax call from a unique function.

So... Two questions in fact:

Is my browser receiving the "echo" in live?

If Yes: How do I Show it live?

If No: How do I send it Live? And how do I Show it Live?

Any help would be greatly appreciated.

Thanks

  • 写回答

1条回答 默认 最新

  • dqvrlgi3247 2014-06-11 12:51
    关注

    Is my browser receiving the "echo" in live?

    No, ajax waits for php to finish and then throws out all echoes at once.

    If No: How do I send it Live? And how do I Show it Live?

    I dont know a quick way to show it live but there are workarounds.

    Create multiple ajax functions that will interact with the server to make it seem live. like I said in the comments. With this I am assuming you know how ajax works.

    //javascript
    function f1(){
        //call ajax to tell the server send a start response
    }
    
    //php
    echo "<img src='loading.gif'>";
    //or something like it.
    
    //ajax function to make the server do the data.
    function f2(){
        //call ajax to tell the server to start and save data in a session
        //Or something like it also set div to be changed to a hidden div.
    }
    
    //php
    //run the required script. then echo a finished response that can be found by js.
    //to make it seem extra live you can split this up in different parts.
    //so you can show progress to the client side. like step 1 of 5 complete.
    
    //ajax function 3 for finished
    function f3(){
        //tell server to echo results once f2 is finished;
    }
    
    //php
    //echo results loaded from where you saved it.
    //probably session, delete the session when finished.
    
    评论

报告相同问题?

悬赏问题

  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?