Skip to content

Instantly share code, notes, and snippets.

@tuckbloor
Last active August 29, 2015 14:27
Show Gist options
  • Save tuckbloor/aef85a81a2bd2f64e3c9 to your computer and use it in GitHub Desktop.
Save tuckbloor/aef85a81a2bd2f64e3c9 to your computer and use it in GitHub Desktop.
How To Open A PDF File With JSONP
<script>
$('.pdf').on('click', function() {
var revision_id = $(this).data('revision');
$.ajax({
url:'URL/?revision_id=' +revision_id,
dataType: 'JSONP',
jsonpCallback: 'callback',
jsonp: 'callback',
success:function(response){
//do stuff
},
error:function(xhr, textStatus, errorThrown){
alert("Something Happened");//windows 10 style error warning
}
});
});
callback = function(data){
window.open("your_url/" + data);
}
</script>
header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");
$revision_id = (int)$_GET['revision_id'];
$array = ['revision_id' => $revision_id];
//get the url of pdf here with a variable called $file from a new Application_Model_Modelname passing $array
$file = str_replace('/', '//', $file);
echo $_GET['callback'] . '('.json_encode($file).')';
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment