中断 php 进程以获取 js 变量
我问了关于 PHP 破解的问题。 我需要停止执行php进程线程,而javascript执行获取变量值操作(代码由php生成)。
示例:
<?php
print get("prompt('put your name here');");
// this will generate $.ajax( ... data: { 'return':prompt('put your name') } ... )
?>
PHP 函数“get”必须打印 javascript 代码(返回标头和内容),但不要停止 php 的执行。他必须从浏览器中观看功能结果。 (通过ajax返回)。
如何使用临时输出停止 php 执行并在 php 代码完成后返回查询结果。 或者...建议我解决这个问题。
(我需要同步获取提示对话框结果)
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是它的工作方式 - 您需要将 JavaScript 的输出和通过 Ajax 的响应作为 PHP 中的两个单独的请求进行处理。
即:大致方案如下:
PHP 输出包含 JavaScript 等的相关 HTML,到此 PHP 脚本的执行结束。
客户端 JavaScript 执行所需的处理并对服务器上的 PHP 脚本进行 AJAX 调用。这可以是相同的 PHP 脚本(您可以通过
$_GET
或$_POST
变量打开提供的页面“模式”),也可以是完全不同的 PHP 页面。然而,重要的是要认识到,从 PHP 的角度来看,这是完全不同的脚本调用。要记住的关键一点是 HTTP 本质上是无状态的,因此您需要确保在 AJAX 请求中传递 PHP 脚本所需的所有相关信息。
此外,理想情况下,您应该确保为禁用 JavaScript 的用户提供一个后备系统,尽管目前该系统在一定程度上已被半途而废。
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.