-1

How do I connect to another location

I want to download data from an external site

i want to include it in site my

Used this

<head>
<script>
$(function(){
    $.ajax({
        url: "https://www.google.com.sa" ,
        datatype: "html",
        success : function(){
            $("#abc").append(data);
        }
    });
});
</script>
</head>

<body>
<div id='abc'></div>    
</body>

But did not succeed

I tried this

<script>
$(function(){
    $("#abc").load("http://google.com");
});
</script>

But did not succeed

I want to download data from an external site

Correctly ??

But how??

khaled
  • 13
  • 1
  • 6
  • What exactly are you trying to do? – ATOzTOA Jan 05 '13 at 11:57
  • Same origin policy: http://en.wikipedia.org/wiki/Same_origin_policy. How to do it correctly really depends on what exactly you are trying to achieve. Do you want to load any data from an external site or from an internal site? What do you want to do with the data? – Felix Kling Jan 05 '13 at 12:01
  • *"I want to download data from an external site"*: Do you want to include it in your site? Do you want to parse it and extract information and store it in a DB? Please explain your problem properly. – Felix Kling Jan 05 '13 at 12:12
  • i want to include it in site my – khaled Jan 05 '13 at 12:23
  • Then you have to use an `iframe`. Though many sites don't want to be included in other sites and you should respect that. – Felix Kling Jan 05 '13 at 14:21

2 Answers2

0

Your first code works fine. But, you have to execute it through a webserver, not locally.

Look at this thread: Origin null is not allowed by Access-Control-Allow-Origin

Community
  • 1
  • 1
ATOzTOA
  • 34,814
  • 22
  • 96
  • 117
0

you cannot use java script to call outside the domain, from which the JS was loaded. another thing that you can try is using iframes

Try this way,

$(document).ready(function(){
    $("iframe").attr("src","http://www.google.com")
})
Sibu
  • 4,609
  • 2
  • 26
  • 38