Skip to content

Instantly share code, notes, and snippets.

@desmondhume
Created June 7, 2014 17:14
Show Gist options
  • Save desmondhume/18aec0622f06d57afcbb to your computer and use it in GitHub Desktop.
Save desmondhume/18aec0622f06d57afcbb to your computer and use it in GitHub Desktop.
Ajax single page
<?php
function curl_download($Url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
if(isset($_GET['ajax'])) {
echo curl_download('http://www.example.com');
exit;
}
?>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<script>
$(function() {
var myhtml;
$.ajax({
url: '/',
data: {ajax: true},
success: function(html) {
myhtml = html;
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment