DasSaffe
DasSaffe

Reputation: 2198

AngularJS values from MySQL DB

I read several tutorials about it, but I can't figure out what is wrong:

HTML

<!DOCTYPE html>
<html ng-app="dfuApp" ng-controller="dfuController">
    <head>
        <title>Angular JS Test</title>
    </head>
    <body>
        <div>
            current status: {{status}}
        </div>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
        <script type=”text/javascript” src="js/app.js"></script>
    </body>
</html>

aps.js

//Define an angular module for our app 
console.log('here');
var app = angular.module('dfuApp', [])

app.controller('dfuController', function ($scope, $http) {
    getStatus();
    function getStatus() {
    $http.get("../getStatus.php").success(function (data) {
        $scope.status = data; //the data are stored in projects
        });
    };
});

getStatus.php

<?php

$mysqli = new mysqli(credentials);

// The mysql database connection script

$query = "select statusid from metadata";
$result = $mysqli->query($query) or die($mysqli->error . __LINE__);

$arr = array();
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $arr[] = $row;
    }
}

//JSON-encode the response
echo $json_response = json_encode($arr);

This example was taken from several example-Sites like this, that and finally this here.

I double-checked it and I can't find any errors. In my console, it says:

[$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=dfuApp&p1=Error%3A…gleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.15%2Fangular.min.js%3A17%3A381)

which finally leads to the following:

This error occurs when a module fails to load due to some exception. The error message above should provide additional context.

Any Idea why this isn't working? What am I missing?

Upvotes: 2

Views: 110

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

It should be " instead of

Convert this

<script type=”text/javascript” src="js/app.js">

to this

<script type="text/javascript" src="js/app.js">

Upvotes: 3

Related Questions