Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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("\n","",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

share|improve this question

2 Answers

You use directly in browser

wordstat/ajax?page=page&url=url

but ajax use

wordstat/ajax?query='+query+'&page='+page+'&id='+id

Perhaps different arguments give you different results.

share|improve this answer
I tried use in ajax 'wordstat/ajax?query='+query+'&page='+page but it still not work – Виктор Новиков Jul 10 at 3:53
You use in browser address without query. Ajax use address with query. You use query as word in rating.php – furas Jul 10 at 4:06

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("\n","",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

share|improve this answer
So what was the problem ? Write more info in your answer. – furas Jul 10 at 4:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.