Created
July 25, 2012 17:55
-
-
Save yinyin/3177531 to your computer and use it in GitHub Desktop.
JSONP experiment w/ PHP and jQuery
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 | |
header('Content-Type: application/json'); | |
$callback = trim($_GET['callback']); | |
if(!empty($callback)) | |
{ echo $callback, '('; } | |
echo '{"status": 0, "tstamp": ', time(), '}'; | |
if(!empty($callback)) | |
{ echo ');'; } | |
?> |
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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> | |
<script> | |
<!-- // | |
$(document).ready(function() { | |
$.get("http://webserver.local/endpoint.php", function(data) { | |
$("#d-place").text(data.tstamp); | |
}, "jsonp"); | |
}); | |
// --> | |
</script> | |
</head> | |
<body> | |
<p>d = <span id="d-place">.</span></p> | |
</body> | |
</html> | |
<!-- | |
vim: ts=4 sw=4 ai nowrap | |
--> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment