I asked that question about PHP breaking. I need stop execution of php process thread, while javascript performs get variable value operation (the code is generating by php).
Example:
<?php
print get("prompt('put your name here');");
// this will generate $.ajax( ... data: { 'return':prompt('put your name') } ... )
?>
the PHP function ''get'' must print javascript code (return headers and content), but don't stop execution of php. He must watching a result of function from browser. (via ajax return).
How i can stop php execution with TEMPORARY output and returning query result after php code complete. Or... advice me any solution of this problem.
(I need get prompt dialog result synchronously)
Thanks!
This isn't the way it works - you need to handle the output to/of the JavaScript and the response via Ajax as two separate requests within PHP.
i.e.: The general scheme is as follows:
PHP outputs the relevant HTML containing JavaScript, etc. The execution of this PHP script ends at this point.
The client-side JavaScript carries out the required processing and makes an AJAX call to a PHP script on the server. This can be the same PHP script (you could switch on a provided page "mode" via a $_GET
or $_POST
variable) or it could be a different PHP page entirely. However, it's important to realise that from PHP's perspective it's a completely different script invocation.
The key thing to remember is that HTTP is inherently stateless, so you need to ensure that you pass all of the relevant information the PHP script requires in the AJAX request.
Additionally, you should ideally ensure that there's a fallback system in place for user's that have JavaScript disabled, although that's falling by the wayside to a certain extent these days.