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条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?