Whois lookup with Ajax

Hi there,

I'm trying to do a whois lookup from one of the domain sources here in South Africa. I've setup the form to submit with an ajaxSubmitButton and replace the result in a div called whois_data, however I end up getting some jquery error

Whois server GET url looks like this



http://co.za/cgi-bin/whois.sh?Domain=yourDomainName&Enter=Enter


Here's my WhoisForm's code






<div class="yiiForm">


<?php echo CHtml::beginForm(); ?>





<?php echo CHtml::errorSummary($whois); ?>





<?php echo CHtml::activeLabel($whois,'domain'); ?>


<?php echo CHtml::activeTextField($whois,'domain',array('name'=>'Domain')).'co.za' ?>





<div class="whois_data">


    <!-- data -->


</div>





<?php echo CHtml::ajaxSubmmitButton('Enter',


    "http://co.za/cgi-bin/whois.sh",


    array('replace'=>'.whois_data','type'=>'GET','dataType'=>'text'),


    array('name'=>'Enter')); ?>


</div>





<?php echo CHtml::endForm(); ?>


This is the error returned with Firebug



Access to restricted URI denied" code: "1012


xhr.open(type, s.url, s.async);


I actually want to make some alterations on the text that get returned from the whois server so I'll have to store it as a string.

How would I go about acieving this?

There are some restrictions due to cross-domain policy.

In most cases you cannot request external site via ajax calls.

Is there any other way of getting the results from the whois request and displaying in a Yii view?

Ok, found a solution with a little help from this post by Gapz here

I create a function in a Helper component class and called it via Ajax

Here's my code



<?php





class Helpers


{


    public static function cozaCurlCheck($domain)


    {


        $ch=curl_init();


        $url="http://co.za/cgi-bin/whois.sh?Domain=";


        $url.=$domain;


        curl_setopt($ch,CURLOPT_URL,$url);


        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,0);


        curl_setopt($ch,CURLOPT_TIMEOUT,4);


        curl_setopt($ch,CURLOPT_REFERER,"http://co.za/whois.shtml");


        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);


        $data=curl_exec($ch);	





        if(curl_error($ch)=="")


        {


            echo $data;


        }


        else


        {


            curl_close($ch);


            $layout="<tr>n<td>nAn Error Occured in connecting to the whois server</td>n</tr>n";


	    echo $layout;


            exit;


        }


    }


}





?>





SiteController



<?php





    public function actionRegister()


    {        


        if(Yii::app()->request->isAjaxRequest)


        {


            if(isset($_POST['domain']))


            {


                echo Helpers::cozaCurlCheck($_POST['domain']);


            }


        }


        else


        {


            $this->render('register');


        }


    }


?>


Register View



<?php


<div class="yiiForm">


<?php echo CHtml::form(); ?>





<?php //echo CHtml::errorSummary(); ?>





Domain


<?php echo CHtml::textField('domain').'co.za' ?>








<?php echo CHtml::ajaxSubmitButton('Enter',


    array('register'),


    array('type'=>'POST','update'=>'#whois_data'),


    array('name'=>'Enter')); ?>


</div>





<div id="whois_data">


    <!-- data -->


</div>





<?php echo CHtml::endForm(); ?>


?>


Voila, the returned text that is returned needs to be formatted and that's a wrap