Try the following example:
ajax.php
<?php
$phpArray = array(0,1,2,3);
echo json_encode($phpArray);
?>
index.html
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready( function() {
$('#clickme').click(function() {
$.ajax({
type: 'POST',
url: 'ajax.php',
data: 'id=somedummydata',
dataType: 'json',
cache: false,
success: function(result) {
var jsArray = [];
for (i = 0; i < result.length; i++) {
jsArray.push(result[i]);
}
$('#result').html(jsArray[0]);
},
});
});
});
</script>
</head>
<body>
<div id="result">Ajax input</div>
<div id="clickme">Click Me!</div>
</body>
</html>