Last active
August 29, 2015 14:27
-
-
Save tuckbloor/aef85a81a2bd2f64e3c9 to your computer and use it in GitHub Desktop.
How To Open A PDF File With JSONP
This file contains 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
<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> |
This file contains 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
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