1

I need to call another page for example http://www.google.com to my specific div. I had done using ajax...

$.ajax({
     url : 'http://www.google.com',
     success : function (data)
     {
         $('#my-div').html(data);
     }
});

But it does not work....Is there any better ways instead of using <iframe> ?

Nere
  • 4,097
  • 5
  • 31
  • 71
  • If I call the page inside my system..there is no problem...but in my case, i need to call third party page... – Nere Jun 04 '15 at 01:41

1 Answers1

0

Your code will not work due to the same-origin policy (if your ajax code is on www.mysite.com, you can only send ajax requests to other files on www.mysite.com).

Here are 2 common solutions:

1) If you can write server side code, you can ajax your own domain, scrape www.google.com using cURL and return the response.

2) With ajax you can use JSONP but one condition is that the server (www.google.com in your case) is configured for JSONP responses. Checkout the jquery doc for how to go about JSONP.

galki
  • 8,149
  • 7
  • 50
  • 62
  • So its means I can not call another page if I'm not using CURL? – Nere Jun 04 '15 at 01:52
  • If it's PHP look up http://php.net/manual/en/curl.examples-basic.php and http://php.net/manual/en/function.file-get-contents.php. For JSONP check out http://api.jquery.com/jquery.getjson/#example-0. But JSONP will only work if the site you are targeting is letting it work. – galki Jun 04 '15 at 02:03
  • Yes I'm using PHP ...Actually i need to call another page of survey,...the page was https and it does not work to use file-get-contents.... – Nere Jun 04 '15 at 02:08
  • Ok. Check this out for cURL over https http://stackoverflow.com/questions/4372710/php-curl-https – galki Jun 04 '15 at 02:15
  • 1
    I see. This is file_get_contents over https http://stackoverflow.com/questions/1975461/how-to-get-file-get-contents-work-with-https – galki Jun 04 '15 at 03:07