Skip to content

Instantly share code, notes, and snippets.

@brizandrew
Created July 25, 2017 20:19
Show Gist options
  • Save brizandrew/0a3518e8390efa444033da1e796454b1 to your computer and use it in GitHub Desktop.
Save brizandrew/0a3518e8390efa444033da1e796454b1 to your computer and use it in GitHub Desktop.
Routing get requests through a php file to go around cross-site-origin restrictions.
function get(url){
var dataString = 'url='+url;
$.ajax({
url: "get.php",
type: "POST",
data: dataString,
success: function(html) {
// Stuff...
// HTML = the page
},
error: function (jqXHR, status, err) {
throw new("Error: get.php connect failure.");
}
});
}
<?php
if(isset($_POST['url'])){
$curl = curl_init($_POST['url']);
$resp = curl_exec($curl);
curl_close($curl);
echo $resp;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment