douba2011 2011-07-19 20:48
浏览 48
已采纳

打破获取js变量的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!

  • 写回答

1条回答 默认 最新

  • doukuipai8544 2011-07-19 20:50
    关注

    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:

    1. PHP outputs the relevant HTML containing JavaScript, etc. The execution of this PHP script ends at this point.

    2. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能