Dear pals,

I am newbie in RESTful services . I need to call a GET Verb in Server . I know 2 methods

  1. Ajax Call

we can write it as

         url: url, 
         dataType: "html",
         type: 'GET', 
         data: "id="+id+"&type="+type, 
         success: function(data){ 
            $('table #sample-boxed-2-pagination th a').each(function(){
                //this.href = this.href.replace(sub_url, main_url);
                var value = this.href.split('?');
                  this.href = this.href.replace(value[0], sub_url);


But I know it's not working in Cross domain scenario . Please advise a method to work same in all domains .

  1. Using file_get_contents() function like

    $response = file_get_contents('');

I know I can call POST verb using cURL as

$ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, "http://localhost/simple_rest_master/test");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);

    $data = array(
        'username' => 'foo',
        'password' => 'bar'

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

    $contents = curl_exec($ch);


    echo $contents;  // manipulate response

Do you can advise the syntax of GET call using cURL ?

Waiting your fast reply



Member Avatar

Can you use jsonp? That's x-domain, but the server needs to be set up to return data in jsonp.

Dear diafol,
My issue to use jsonp is that most of my data return is in HTML format(78%) . So using jsonp is not approriate to me. Please advise any proxy solution in this case .


Member Avatar

If your host supports it, the file_get_contents is a simple to use solution. cURL is a little more involved as you know. Do you need to use cURL?