Created
July 25, 2017 20:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | |
} | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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