Created
January 23, 2012 18:25
-
-
Save ynonp/1664664 to your computer and use it in GitHub Desktop.
PHP JSON Example
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' ); | |
$a = array(10, 20, 30); | |
print json_encode($a); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>PHP JSON Example</title> | |
</head> | |
<body> | |
<div> | |
And the winner is ... | |
<span id="result"></span> | |
</div> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
var div_el = document.querySelector('#result'); | |
$.get('get_numbers.php', function(numbers) { | |
console.dir(numbers); | |
// put the second into the div | |
div_el.innerHTML = numbers[1]; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment