I'm trying to learn Ajax and Json so I can build on it to pass php data to my web page with out refreshing. I am using the following example but the result html page does not show anything. Can some one please let me know what I'm doing wrong.
Html code
<html>
<body>
<script src="jquery.js"></script>
<script>
$.ajax({
url: "test.php",
dataType: "json", //the return type data is jsonn
success: function(data){ // <--- (data) is in json format
alert(data.test1);
//parse the json data
}
});
</script>
<div id = "data"></div>
</body>
</html>
PHP code named test.php
<?php
$test = array();
$test['test1'] = '1';
$test['test2'] = '2';
$test['test3'] = '3';
echo json_encode($test);
//echo nothing after this //not even html
?>