【问题标题】:cUrl request every 2 seconds and echo resultscUrl 每 2 秒请求一次并回显结果
【发布时间】:2014-02-28 10:43:01
【问题描述】:

我希望每 2 秒发送一次 cUrl 变量,并在页面中显示结果。 我是使用 Ajax 的魔杖,但我如何使用函数参数发送 cUrl 详细信息?

感谢帮助,祝你有美好的一天:)

【问题讨论】:

    标签: php ajax function curl


    【解决方案1】:

    你可以每隔两秒调用一次你的 ajax 函数,就像这个 uning setInteval js 函数

    setInterval(your_ajax_function,2000); // call your_ajax_function in every 2 seconds
    
    function your_ajax_function()
    {
        // ajax function statements here
        // and send request to the php file
        // get output from php file as response
        // show response in your desired div
    }   
    

    现在在 php 文件中你可以调用 curl 函数等并将输出作为 echo

    【讨论】:

    • 但是,我需要每 2 秒重播一次 php 函数。我如何使用 ajax 发送 php cUrl 请求?
    【解决方案2】:

    与所有 PhP 代码一样,带有 PhP 的 CURL 仍然是基于服务器的。我自己能想到的每 2 秒发送一次请求的唯一方法是强制每 2 秒刷新一次相关页面。

        $requiredPage = "example.com";
        header('Refresh:2;url='.$requiredPage);
    

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2020-02-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多