dsfbnhc4373 2013-09-23 13:04
浏览 14

jQuery将数据发送到php文件然后再返回

i have a problem with sending data to a php file and then back again (with jQuery).

I know the $.post -> .done function.

My jQuery looks like:

$.post("client.php", { 
    request: request 
})
 .done(function( data ) {
     $("#requestdiv").html(data);
 });

The client.php connects to a server, the server returns a unique number to the client(1). After this (and this is the Problem) the client.php file is loading as long as another client submits the request or server close connection.

But client 1 needs the unique number. Because the person from client 1 tells the person from client 2 (by word of mouth) the unique number and client 2 submit the unique number to the server. After this the server answers client1 and client2, close the connection and the file finishes loading.

The post to client.php works fine. My problem is how can i receive the data although the file did not finish loading (because the client - server connection is still open)?

Thanks for helping..

Update:

The read() method from client.php.

    while ($data = socket_read($this->m_sock, $length, PHP_NORMAL_READ)) {
       if ($data) {
          if (strpos($data, "
", $start) != false) {
            $end = strpos($data, "
", $start);
            $result = substr($data, $start, $end);
            $this->onCommandLine($result);
          }
      } else {
          break;
      }
    }

This method is loading as long as the server close the connection. Because of this, the jQuery do not get a result in data. The server closes the connection after the transaction has finished.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看