[英]Wait function that receives data in PHP
Can you send me in the right direction for writing a Wait function in PHP? 您可以向我发送正确的方向信息,以便用PHP编写Wait函数吗? I'm using procedural code style.
我正在使用过程代码样式。
The scenario is as following: 场景如下:
I need guidance in writing the wait and resume function. 我在编写等待和恢复功能时需要指导。
This defentely sounds like you need to use AJAX. 听起来确实像您需要使用AJAX。 jQuery gives you some comfortable ways to solve your Problem.
jQuery为您提供了一些舒适的方法来解决您的问题。
$.post( "test.php", { name: "John", time: "2pm" })
.done(function( data ) {
alert( "Data Loaded: " + data );
});
This is a code example from https://api.jquery.com/jQuery.post/ . 这是来自https://api.jquery.com/jQuery.post/的代码示例。 You might have a look at https://api.jquery.com/jQuery.ajax/ .
您可以看看https://api.jquery.com/jQuery.ajax/ 。
This AJAX function calls the script test.php with the given parameters as POST variables. 此AJAX函数使用给定参数作为POST变量调用脚本test.php。 You will recieve an answer (data), which you can use in your JS afterwards.
您将收到一个答案(数据),然后可以在JS中使用它。 I think the done() function does exactly what you are asking for.
我认为done()函数完全可以满足您的要求。 To have some consistency between the languages you could work with JSON objects.
为了使语言之间具有一定的一致性,可以使用JSON对象。
You cannot actually stop PHP from executing. 您实际上无法阻止PHP执行。 Thats why you will use a certain file which handles your request.
因此,您将使用某个文件来处理您的请求。
The people here said that Ajax is needed to do this. 这里的人们说,需要Ajax来做到这一点。 This is true.
这是真的。 But, it's not the only option available.
但是,它不是唯一可用的选项。 Using cURL is an option too, and having CURLOPT_RETURNTRANSFER (which returns the value after the transfer) set it does what I needed to do:
使用cURL也是一个选项,设置CURLOPT_RETURNTRANSFER(在传输后返回值)可以满足我的需要:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.