返回AJAX结果每个卷曲请求 [英] return AJAX result for each cURL Request

查看:158
本文介绍了返回AJAX结果每个卷曲请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我的想法是做某种形式的现场卷曲结果系统,其生产的直播结果当执行每个请求,比如我会具有需要被经由卷曲请求访问的网站的列表的表,其中在每次卷曲响应我需要的数据被发送回使用AJAX功能I最初所作的呼叫到它执行这个文件我的网页的结果请求环

Basically, my idea is to do some form of "live cURL results" system which is producing live results when each request is performed, for example I'll have a table with a list of websites that need to be accessed via a cURL request in which upon the result of each cURL response I need data to be sent back to my page using the AJAX Function I initially made the call to the file which performs this loop of requests

<?
    foreach($database['table'] as $row) {
       curl_init($row['url']);
       //the rest of the cURL request etc...

       //SEND cURL RESPONSE BACK TO AJAX AFTER EACH ROW!!!
    }
<?

那么我想它,因为它们发生返回,而不是等待完整的脚本返回他们一下子之前完成的结果为每卷曲的反应。

这可能吗?如果是的话,我会仍然使用普通的 AJAX 请求?

Is this possible? if so would I still use a normal AJAX request?

推荐答案

这个怎么样?

您分解entie过程分为3

You break down the entie process into 3

处理1

您发送一个Ajax请求访问数据库,并发送回URL列表的浏览器页面的PHP页面。 [只是呼应的URL] [使用分隔'|'分离结果的网址。]

You send an ajax request to the php page that access the database and send back the list of urls to the browser page. [simply echo the Urls ] [use a separator '|' to separate the result urls.]

处理2

以上过程的AJAX成功处理函数现在将调用一个新的JavaScript函数,它的下面。

The ajax success handler function of the above process will now call a new JavaScript function that does the below.

拆分URL列表INT数组。

split the url list int an array.

处理3 发送的网址列表逐一用一个又一个的AJAX功能的服务器。

Process 3 Send the urls list one by one to the server using a another ajax function.

这样,只有一个网址被立即处理,结果被送回尽快处理

This way only One url is processed at once and results are send back as soon as it is processed

下面是在JavaScript函数的原型来电,code是不是真实的,但你它是如何工作的总体思路。

Below is the prototype of function calls in JavaScript, the code is not real, but you get an overall idea about how it works.

function ajaxCall_1()
{
    // get url lsit from server
    .onSuccess{
        process_url(data);
    }
}


function process_url(data){
    var url_array = data.split('|')

    fetch_urls(url_array,0); // sends the first url for processing
}

function fetch_urls(url_array,position){

  if(position < url_array.lenght){ // not exceeding the array count 
    ajax_call2(url_array[position],url_array,position); 
  }
}

function ajaxCall_2(url,url_array,position)
{
    // get url acced by  curl and send back the result
    .onSuccess{
        // do whatever with the data you want
        fetch_urls(url_array,position++) // or position+1 // to fetch the next url
    }
}

这篇关于返回AJAX结果每个卷曲请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆