Ajax Call to PHP - TypeError - obj is undefined error
Trying to read ASCI color codes in order to see them on the screen. I am reading a file that is a
json file to start with. My code is below. The response is in the attachment Created by Web Developer tools.
Here is my
php code.
- <?php
// Read JSON file
$json = file_get_contents('./ASCIColors.json');
echo $json;
?>
Here is my
html code.
<!DOCTYPE html>
<!-- Comments about the program -->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title> Pizzi Contacts v2.1 21 Jan 2016 - contactConnect.html</title>
<script src="../../jquery/jquery-2.1.1.js"></script>
<script type="text/javascript">
$.ajax({
type: "POST",
dataType: "json",
url: "response.php", //Relative or absolute path to response.php file
//data: {}, not used - read from file
success: function(ret) {
$.each( ret[0], function( key, value ) {
alert($(".the-return").append("<style>div{background-color: "+value+"</style>)"));
});
successmessage = 'Data was succesfully captured';
$("label#successmessage").text(successmessage);
},
error: function(ret) {
successmessage = 'Error';
$("label#successmessage").text(successmessage);
},
});
</script>
</head>
<body>
<div class="the-return">
[HTML is replaced when successful.-<br>
-----------------------------------<br>
-----------------------------------<br>
-----------------------------------<br>
-----------------------------------]<br>
</div>
</body>
</html>