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.