dphe5602 2013-07-10 01:44
浏览 27
已采纳

AJAX。 PHP。 卷曲。 Ajax请求到站点,使用另一种编码

I try to parse one page from my another site. For it i use cUrl

Request (send data to script):

        $.ajax({
            url: 'wordstat/ajax?query='+query+'&page='+page+'&id='+id,
            success: function(data){
                alert(data);
            }
        });

This script (wordstat/ajax), do request to my second site via controller:

Controller:

public function ajax()
{
    $this->model->auth();
    echo $this->model->parse_uri($_GET['page'],$_GET['query']);

}

Model:

public function parse_uri($url,$word)
{
    curl_setopt($this->curl, CURLOPT_URL, "http://wordstat/rating.php?url=".$url."&word=".$word."&gap=3");

    $html = mb_convert_encoding(str_replace("
","",curl_exec($this->curl)), "utf-8", "windows-1251");
    preg_match('/<span style="font-size:14px" class=red>(.*)<\/span>/U',$html,$matches);
    return $matches;
}

If i put in browser http://localhost/wordstat/ajax?page=page&url=url and open this page, then she return value of <span style="font-size:14px" class=red> of another site correctly

But when i do it via Ajax request, it's always return empty Array

What i doin wrong? Sorry for bad english

  • 写回答

2条回答 默认 最新

  • douqianzha6213 2013-07-10 04:05
    关注

    Problem resolved

        $url = str_replace(" ","",$url);
        $word = str_replace(" ","",$word);
    
        curl_setopt($this->curl, CURLOPT_URL, "http://parser/rating.php?url=".$url."&word=".$word."&gap=3");
    
        $html = str_replace("
    ","",curl_exec($this->curl));
        preg_match('/<span style="font-size:14px" class=red>(.*)<\/span>/U',$html,$matches);
    
        return $matches;
    

    Thanks to anyoune, who tried help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?