troubleshooting Question

What am I doing wrong with this Angular "get" example?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
Angular
5 Comments1 Solution593 ViewsLast Modified:
I'm going through the W3 course on Angular and I'm working through this example: https://www.w3schools.com/angular/tryit.asp?filename=try_ng_customers_mysql

Here's my "term_list_json.php" code:

<?php

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

require_once("term_class_pdo.php");

$current_discipline="";
$new_list= new TermAdmin;
$term_display=$new_list->term_list();

$output="";

foreach($term_display as $term)
{
	if($output !="") 
	{
		{$output.= ", ";}
	}
	$output.= '{"disicpline": "' . stripslashes($term['discipline']) .'", ';
	$output.= '"term": "' .stripslashes($term['term']) .'", ';
	$output.='"definition"; "'. stripslashes($term['definition']).'"}';
}
$output = '{"records": ['.$output.']}';

echo $output;

?>

You can see it live at http://brucegust.com/adm/term_list_json.php

Now, here's my code on the Angular side:

<!DOCTYPE html>
<html lang="en">
<head>
<title>Angular Tutorial</title>
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<style>
table, th , td {
  border: 1px solid grey;
  border-collapse: collapse;
  padding: 5px;
}
table tr:nth-child(odd) {
  background-color: #f1f1f1;
}
table tr:nth-child(even) {
  background-color: #ffffff;
}
</style>
</head>
<body style="white-space: normal;">

<div ng-app="myApp" ng-controller="myCtrl">

<table>
	<tr ng-repeat="x in terms">
		<td>{{x.discipline}}</td>
		<td>{{x.term}}</td>
	</tr>
</table>

</div>

<script>
var app=angular.module("myApp", []);
app.controller('myCtrl', function($scope, $http) {
	$http.get("http://brucegust.com/adm/term_list_json.php")
	.then(function (response) {$scope.terms = response.data.records});
});
</script>

<p>With the "ng-options" directive, the selected value can be an object...</p>

</body>
</html>

When you run the page at http://brucegust.com/adm/angular/json_retrieval.php, you get a blank screen, save some text. But there's a huge error that I've got pictured below.

Now sure what I'm doing wrong or how to process that error.

What do I need to change?

Thanks!
ASKER CERTIFIED SOLUTION
Jim Riddles
Prepress/OMS Specialist

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros