抓取页面使用curl - in PHP它工作得很好,但当我使用ajax有一个问题


fetching a page using curl - in php it works fine but when i use ajax there is an issue

我有一个php页面curl下面的地址。它通过一些xpath查询检索页面并返回/回显结果。

当我通过浏览器访问这个页面时,它工作得很好,没有错误显示,结果正在返回。

然而,当我试图通过ajax访问这个页面没有返回ajax,它似乎有点卡住。

事件的流程是:我做ajax调用我的PHP页面。在该页中,我执行crul和xpath查询,并将结果返回给ajax。

这是我试图检索的页面。

http://www.zara.com/webapp/wcs/stores/servlet/product/us/en/zara-us-W2012-s/337006/908067/FANTASY%20MINI%20SKIRT%20WITH%20DIAMANTE

奇怪的是php没有显示任何错误我已经把error_reporting (-1);设置为显示所有错误,但是仍然没有

我是这样做curl调用的:

$url = 'http://www.zara.com/webapp/wcs/stores/servlet/product/us/en/zara-us-W2012-s/337006/908067/FANTASY%20MINI%20SKIRT%20WITH%20DIAMANTE';
$pageData = curl_init($url);
$userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13";
curl_setopt($pageData, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($pageData, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($pageData, CURLOPT_USERAGENT, $userAgent);
    // - update
    // echo "notification";
    // exit;
    //
echo $to_return = curl_exec($pageData);

这是ajax调用:

var ajax_url = 'http://www.somedomain.com/f/ajax_func.php';
var url_to_search = 'http://www.zara.com/webapp/wcs/stores/servlet/product/us/en/zara-us-W2012-s/337006/908067/FANTASY%20MINI%20SKIRT%20WITH%20DIAMANTE';
$.ajax({
    type: "POST",
    url: ajax_url,
    data: { ajax_search_product: "ajax", url_to_search: url_to_search}
    }).success(function(data) {
        alert(data);
})

我错过了什么吗?这在PHP中很尴尬但在ajax中会出现无法解释的错误

Please add error function in your ajax to know what the status and error is...
error:function(xhr,err){
alert("ERROR : "+err);
    alert("readyState: "+xhr.readyState+"'nstatus: "+xhr.status);
    alert("responseText: "+xhr.responseText);
}
相关文章: