<div class="grid--cell fl1 lh-lg">
<div class="grid--cell fl1 lh-lg">
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, <a href="/help/reopen-questions">visit the help center</a>.
</div>
</div>
</div>
<div class="grid--cell mb0 mt8">Closed <span title="2012-05-24 14:47:46Z" class="relativetime">7 years ago</span>.</div>
</div>
</aside>
My Simple code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="jquery.js"></script>
<script type="text/javascript">
$(function(){
$.get("http://www.facebook.com",function(data){
alert(data);});
});</script></head>
<body>
</body>
</html>
It should alert the facebook content but it is not doing so
UPDATE
Now iam using php
<?php
$str=file_get_contents("http://www.facebook.com");
echo strip_tags(htmlspecialchars($str));
?>
Why it is not removing tags?
</div>
I guess you have just been blocked by the browser due to the Same Origin Policy. See the console, and you will have a warning if you try to do this.
Without Cross-Origin Resource Sharing or a server-side proxy, you cannot read cross-domain pages.
As far as I know, the only way to do this is to have a server-script on your domain read the foreign page (wget, curl, fopen, what else is there) and return it to your page. Your server acts like a "bridge" to read the remote page.
You might have heard of JSONP which does not have cross-domain restrictions, but what you are retrieving this way is not HTML/pages but scripts.
You cannot request content from external websites due to the Same Origin Policy unless using JSONP. However, because you are requesting HTML this is not applicable.
The alternative is to make a server-side proxy to get the HTML of the facebook.com homepage, and then provide that local URL to the $.get()
function.
If youre using php on the serverside. You could create a service that returns the html using:
$html = file_get_contents('http://www.facebook.com');
ASP.NET:
using(WebClient client = new WebClient())
{
string html = client.DownloadString("http://www.facebook.com'");
}
You can make ajax requests in same domain only
however you can use JSONP to make cross-domain requests
http://en.wikipedia.org/wiki/JSONP
Refer to this article on ibm developerworks:
http://www.ibm.com/developerworks/library/wa-aj-jsonp1/